中的c>标签和头 code> widget dataprovider 。 这是我的代码: <?= GridView :: widget(['dataProvider'=> $ dataProvider,'列'=> [ ['class'=>'yii\grid\DataColumn','value'=> function($ data){ return $ data-> myTitle; },'headerOptions'=> ['style'=>'text-align:center'],'header'=> ;'页面标题','label'=>'标题'],]); ?> 执行标题和标签执行相同的功能 如何在 $ data-> myTitle ? 这里我的输出屏幕: 我想要页面标题,状态,修改日期应该是活动的。 p> 提前感谢解决方案找到答案。 请在搜索模型中为ActiveDataProvider添加属性。 $ dataProvider = new ActiveDataProvider (['query'=> $ query,'pagination'=> ['pageSize'=> 5,],' '=> ['attributes'=> ['myTitle']],]); 在窗口小部件中添加属性选项: <?= GridView :: widget(['dataProvider'=> $ dataProvider,'列'=> [ ['class'=>'yii\grid\DataColumn','value'=> function($ data){ return $ data-> myTitle; ','headerOptions'=> ['style'=>'text-align:center'],'属性'=>'myTitle',' =>'页面标题'],]); ?> How can I sort with a customized gridview header?Please give the difference between label and header in the Yii2 gridview widget dataprovider.Here is my code: <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ [ 'class' => 'yii\grid\DataColumn', 'value' => function ($data) { return $data->myTitle; }, 'headerOptions' => ['style'=>'text-align:center'], 'header' => 'Page Title', 'label' => 'Title' ], ]); ?>Do header and label perform the same function?How can I perform sorting in $data->myTitle?Here my Output Screen:I want Page Title, Status, Date Modified should be active.Thanks in advance. 解决方案 Found the answer.Please add attributes to ActiveDataProvider in your Search Model.$dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 5, ], 'sort' => ['attributes' => ['myTitle']], ]);Add the attribute option in widget: <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ [ 'class' => 'yii\grid\DataColumn', 'value' => function ($data) { return $data->myTitle; }, 'headerOptions' => ['style'=>'text-align:center'], 'attribute' => 'myTitle', 'label' => 'Page Title' ], ]); ?> 这篇关于我如何做自定义Yii2 gridview排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 03:05