当我尝试在Kartik的gridview中添加第3个groupFooter时,我遇到了分页问题 . 如果我只添加2个groupFooters,它可以正常工作:
如果我添加3个groupFooters,那么一切都变得混乱:
删除索引列也会使事情变得困难(即使有2组,但1组工作正常) .
以下是视图文件中窗口小部件的代码 .
$gridview = GridView::widget([
'dataProvider' => $dataProvider,
'showPageSummary' => true,
'resizableColumns'=>true,
'hover'=>true,
'resizeStorageKey'=>Yii::$app->user->id . '-' . date("m"),
'columns' => [
['class'=>'kartik\grid\SerialColumn'],
[
'attribute'=>'category_id',
'width'=>'310px',
'value'=>function ($model, $key, $index, $widget) {
return $model->category->name;
},
'group'=>true, // enable grouping
'groupFooter'=>function ($model, $key, $index, $widget) { // Closure method
return [
'mergeColumns'=>[[1,3]], // columns to merge in summary
'content'=>[ // content to show in each summary cell
1=>Yii::t('app','Average'). ' (' . Yii::t('app',$model->category->name) . ')',
5=>GridView::F_AVG,
6=>GridView::F_AVG,
],
'contentFormats'=>[ // content reformatting for each summary cell
5=>['format'=>'number', 'decimals'=>0],
6=>['format'=>'number', 'decimals'=>0],
],
'contentOptions'=>[ // content html attributes for each summary cell
1=>['style'=>'font-variant:small-caps'],
5=>['style'=>'text-align:right'],
6=>['style'=>'text-align:right'],
],
// html attributes for group summary row
'options'=>['class'=>'danger','style'=>'font-weight:bold;']
];
}
],
[
'attribute'=>'make_id',
'width'=>'250px',
'value'=>function ($model, $key, $index, $widget) {
return $model->make->name;
},
'group'=>true, // enable grouping
'subGroupOf'=>1, // supplier column index is the parent group,
'groupFooter'=>function ($model, $key, $index, $widget) { // Closure method
return [
//'mergeColumns'=>[[2, 3]], // columns to merge in summary
'content'=>[ // content to show in each summary cell
2=>Yii::t('app','Average'). ' (' . $model->make->name . ')',
5=>GridView::F_AVG,
6=>GridView::F_AVG,
],
'contentFormats'=>[ // content reformatting for each summary cell
5=>['format'=>'number', 'decimals'=>0],
6=>['format'=>'number', 'decimals'=>0],
],
'contentOptions'=>[ // content html attributes for each summary cell
5=>['style'=>'text-align:right'],
6=>['style'=>'text-align:right'],
],
// html attributes for group summary row
'options'=>['class'=>'success','style'=>'font-weight:bold;']
];
},
],
[
'attribute'=>'modele_id',
'value'=>function ($model, $key, $index, $widget) {
return $model->modele->name;
},
'group'=>true, // enable grouping
'subGroupOf'=>2, // supplier column index is the parent group
'groupFooter'=>function ($model, $key, $index, $widget) { // Closure method
return [
//'mergeColumns'=>[[2, 3]], // columns to merge in summary
'content'=>[ // content to show in each summary cell
3=>Yii::t('app','Average'). ' (' . $model->modele->name . ')',
5=>GridView::F_AVG,
6=>GridView::F_AVG,
],
'contentFormats'=>[ // content reformatting for each summary cell
5=>['format'=>'number', 'decimals'=>0],
6=>['format'=>'number', 'decimals'=>0],
],
'contentOptions'=>[ // content html attributes for each summary cell
5=>['style'=>'text-align:right'],
6=>['style'=>'text-align:right'],
],
// html attributes for group summary row
'options'=>['class'=>'warning','style'=>'font-weight:bold;']
];
},
],
[
'attribute'=>'id',
'format'=>'raw',
'value'=>function ($model, $key, $index, $widget) {
return Html::a($model->id, ['view', 'id' => $model->id]);
},
'width'=>'150px',
'hAlign'=>'right',
],
[
'attribute'=>'price_sold',
'width'=>'150px',
'hAlign'=>'right',
'format'=>['decimal', 0],
'pageSummary'=>true
],
[
'attribute'=>'daysToSell',
'width'=>'150px',
'hAlign'=>'right',
'format'=>['decimal', 0],
'pageSummary'=>true
],
],
]);