我使用Kartik expandrow并且父代码工作正常。但是子代码没有根据父代传递的数据进行过滤。
索引文件中的Kartik网格代码 -
'class' => 'kartik\grid\ExpandRowColumn',
'value' => function($model, $key, $index, $column){
return GridView::ROW_COLLAPSED;
},
'detail' => function($model, $key, $index, $column){
$searchModel = new ExpartiesSearch();
$searchModel-> parties_district = $model['district'];
//$searchModel-> billdate = $model['billdate'];
//$searchModel-> payment_date = $model['payment_date'];
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Yii::$app->controller->renderPartial('_exparties', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
},
父搜索查询代码
$subQuery1 = (new Query())
->select(['parties_district','billdate','sum(billamount) as sale'])
->from ('parties')->join('LEFT JOIN','bills','bills.bills_partyname = parties.parties_partyname')
->groupby('parties_district')
->where('billdate != "NULL"');
$subQuery2 = (new Query())
->select(['district','coalesce(sell.sale,0) as totalsale'])
->from('districts')
->leftJoin(['sell' => $subQuery1],'sell.parties_district = districts.district');
$subQuery3 = (new Query())
->select(['parties_district','payment_date','COALESCE(sum(payment_amount),0) as collection'])
->from('payment')
->join('LEFT JOIN','parties','payment.payment_partyname = parties.parties_partyname')
->groupby('parties_district');
$query = (new Query())
->select(['tsell.district as district','tsell.totalsale as sell','coalesce(tcollection.collection,0) as collection'])
->from(['tsell'=> $subQuery2])
->leftJoin(['tcollection' => $subQuery3],'tcollection.parties_district = tsell.district');
$dataProvider = new ActiveDataProvider([
'query' => $query,
//'sort'=> ['defaultOrder' => ['district'=>SORT_DESC]]
]);
if( !($this->load($params) && $this->validate()) ){
return $dataProvider;
}
if($this->from_date && $this->to_date){
$subQuery1->where(['between', 'billdate', $this->from_date, $this->to_date]);
$subQuery3->where(['between', 'payment_date', $this->from_date, $this->to_date]);
}
return $dataProvider;
子查询代码
$subQuery1 = (new Query())
->select(['bills_partyname','billdate','sum(billamount) as sale'])
->from('bills')
->groupby('bills_partyname');
$subQuery2 = (new Query())
->select(['parties_district','parties_partyname','billdate','coalesce(sell.sale,0) as totalsale'])
->from('parties')
->leftJoin(['sell' => $subQuery1], 'sell.bills_partyname = parties_partyname')
->where('billdate != "NULL"');
$subQuery3 = (new Query())
->select(['payment_partyname','payment_date','COALESCE(sum(payment_amount),0) as collection'])
->from('payment')
->groupby('payment_partyname');
$query = (new Query())
->select(['tsell.parties_district as district','tsell.parties_partyname as partyname','tsell.billdate as billdate','tsell.totalsale as sell','COALESCE (tcollection.collection,0) as collection'])
->from(['tsell'=> $subQuery2])
->leftJoin(['tcollection' => $subQuery3],'tcollection.payment_partyname = tsell.parties_partyname');
$dataProvider = new ActiveDataProvider([
'query' => $query,
//'sort'=> ['defaultOrder' => ['district'=>SORT_DESC]]
]);
if( !($this->load($params) && $this->validate()) ){
return $dataProvider;
}
if($this->from_date && $this->to_date){
$subQuery1->where(['between', 'billdate', $this->from_date, $this->to_date]);
$subQuery3->where(['between', 'payment_date', $this->from_date, $this->to_date]);
}
return $dataProvider;
没有错误消息。网格中的行可以通过子视图中的数据不会根据父级进行过滤来扩展。这是与Search data in child view taking input from form in parentview in kartik expandrow in Yii2
相同的问题