无法对 CGridView 小部件的相关列进行排序,Yii 1.1
Can't sort related columns of CGridView widget, Yii 1.1
我正在使用此 DataProvider 来提供 CGridView 小部件,但列仍然无法显示为可点击,当然也不允许排序。
这里出了什么问题?
控制器:
$dataProvider = new CActiveDataProvider( 'SubscriberAuthor', [
'criteria' => [
'with' => [
'subscriber' => [ 'select' => 'name, email' ]
],
'condition' => "author_id = {$author_id} And verified = 1"
],
'sort' => [
'attributes' => [
'name'=> [
'asc'=>'subscriber.name Asc',
'desc'=>'subscriber.name Desc',
],
'email'=> [
'asc'=>'subscriber.email Asc',
'desc'=>'subscriber.email Desc'
]
]
],
'countCriteria' => [ 'condition' => "author_id = {$author_id} And verified = 1" ]
]);
查看:
$this->widget( 'zii.widgets.grid.CGridView', [
'dataProvider' => $dataProvider,
'enableSorting' => true,
'columns' => [ 'subscriber.name', 'subscriber.email' ]
]);
确保在列名称中使用的是 table 名称,而不是关系或模型名称
'attributes' => [
'name'=> [
'asc'=>'subscriber_table.name Asc',
'desc'=>'subscriber_table.name Desc',
],
'email'=> [
'asc'=>'subscriber_table.email Asc',
'desc'=>'subscriber_table.email Desc'
]
当然,问题是我没有使用列的完全限定名称:
'sort' => [
'attributes' => [
'subscriber.name'=> [
'asc'=>'subscriber.name Asc',
'desc'=>'subscriber.name Desc',
],
'subscriber.email'=> [
'asc'=>'subscriber.email Asc',
'desc'=>'subscriber.email Desc'
]
]
]
我正在使用此 DataProvider 来提供 CGridView 小部件,但列仍然无法显示为可点击,当然也不允许排序。
这里出了什么问题?
控制器:
$dataProvider = new CActiveDataProvider( 'SubscriberAuthor', [
'criteria' => [
'with' => [
'subscriber' => [ 'select' => 'name, email' ]
],
'condition' => "author_id = {$author_id} And verified = 1"
],
'sort' => [
'attributes' => [
'name'=> [
'asc'=>'subscriber.name Asc',
'desc'=>'subscriber.name Desc',
],
'email'=> [
'asc'=>'subscriber.email Asc',
'desc'=>'subscriber.email Desc'
]
]
],
'countCriteria' => [ 'condition' => "author_id = {$author_id} And verified = 1" ]
]);
查看:
$this->widget( 'zii.widgets.grid.CGridView', [
'dataProvider' => $dataProvider,
'enableSorting' => true,
'columns' => [ 'subscriber.name', 'subscriber.email' ]
]);
确保在列名称中使用的是 table 名称,而不是关系或模型名称
'attributes' => [
'name'=> [
'asc'=>'subscriber_table.name Asc',
'desc'=>'subscriber_table.name Desc',
],
'email'=> [
'asc'=>'subscriber_table.email Asc',
'desc'=>'subscriber_table.email Desc'
]
当然,问题是我没有使用列的完全限定名称:
'sort' => [
'attributes' => [
'subscriber.name'=> [
'asc'=>'subscriber.name Asc',
'desc'=>'subscriber.name Desc',
],
'subscriber.email'=> [
'asc'=>'subscriber.email Asc',
'desc'=>'subscriber.email Desc'
]
]
]