I’m trying to setup a very simple table using CGridView. However, no matter what I do I cannot seem to make one of the columns in the table sortable.
Below is my code.
This is code inside the model:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('keyword',$this->keyword,true);
$criteria->compare('nums',$this->nums);
$criteria->compare('type',$this->type);
$sort = new CSort();
$sort->attributes = [
'id'=>[
'asc'=>'id',
'desc'=>'id desc'
],
'nums'=>[
'asc'=>'nums',
'desc'=>'nums desc'
]
];
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
'pagination'=>array(
'pageSize'=>50,
),
));
}
This is code inside the view which uses CGridView:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' =>$model->search(),
'columns' => array(
array(
'name' => 'id',
'value' => '$data->id',
'htmlOptions' => array('style' => 'text-align:center')
),
array(
'name' => 'Keywords',
'value' => '$data->keyword',
'htmlOptions' => array('style' => 'text-align:center')
),
array(
'name' => 'Total searches',
'value' => '$data->nums',
'sortable'=>true,
'htmlOptions' => array('style' => 'text-align:center')
),
array(
'name' => 'Search type',
'value' => '$data->type',
'htmlOptions' => array('style' => 'text-align:center')
)
)
));
?>
I just want to get the nums column sortable, but I just can’t seem to get it working. The column is not even clickable.
Any idea what may be wrong?
Thanks!