我正在使用Yii2高级模板。下面是在索引页面上生成Gridview小部件的代码。
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'invoice_id',
[
'label'=> 'Customer',
'value' => function ($model) {
return ucfirst($model->customer->customer_name);
},
'enableSorting'=> TRUE,
],
'invoice_type',
'timestamp' => [
'label' => 'Sale / Purchase Date',
'attribute' => 'timestamp',
'format' => ['date', 'php:y-m-d h:i:s A'],
],
'payment_option',
['class' => 'yii\grid\ActionColumn','template'=>'{view} {delete}'],
],
]);
?>
问题是,尽管使用&#39;标签&#39;和&#39; enableSorting&#39;对于&#39; customer_name&#39;当我使用&#39; value&#39;属性,排序链接消失。如何启用排序链接。还附上我的观点的快照;
解决问题后,当我点击排序链接时,我会收到以下错误。
答案 0 :(得分:0)
尝试修改此列配置,如下所示:
[
'attribute' => 'customer.customer_name',
'label'=> 'Customer',
'value' => function ($model) {
return ucfirst($model->customer->customer_name);
},
],