无论如何我们可以从外部下拉列表更新gridview更新gridview? 我也在使用Pjax ..
示例:当我们要加载相关客户的所有销售订单时。 从下拉列表中选择客户时,需要更改gridview。 这是Yii2。
这个视图下拉列表
function loadcustomerdata(){
var selected = $('#sinvoicepayment-customer_id').val();
$.ajax({
url: '<?php echo Yii::$app->urlManager->createUrl("sinvoicepayment/searchcustomerdata"); ?>',
type: 'POST',
data: {'selected':selected},
datatype: 'json',
success: function(result) {
$.pjax.reload({container:"#receipts"});
},
error: function(data) {
//alert("There may a error on uploading. Try again later");
},
});
return false;*/
}
和JS函数
public function actionSearchcustomerdata(){
if (Yii::$app->request->isAjax) {
$post = Yii::$app->request->post('selected');
Yii::$app->response->format = Response::FORMAT_JSON;
$customer = Mcustomer::find()->where(['idCustomer'=>$post])->one();
$invoice = Sinvoice::find()->where(['id_customer'=>$post])->one();
return ['add'=>$customer->C_address,'contact'=>$customer->C_tel];
}
}
控制器功能
{{1}}