I use CGridView + CActiveDataProvider to build some query page and I can click the column header to sort.
But I try to use some CGridView + CSqlDataProvider, the query function is ok, but I cannot sort by clicking the column header.
I try to search similar questions, first, I add sort attribute in CSqlDataProvider, it works, the data is sort by my condition, but I still cannot click the column to sort.
$dataProvider=new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'keyField' => 'transdate',
'sort'=>array(
'defaultOrder'=>'transdate, accountname',
),
'pagination'=>array(
'pageSize'=>50,
),
));*/
Second, I found lots of post said I should assign “name” value. But it still doesn’t work.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'checking-account-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
array(
'header'=> 'Date',
'name' => '$data[\'transdate\']',
'value' => '$data[\'transdate\']',
'type' => 'raw',
'htmlOptions' => array('style' => 'white-space: nowrap;')
),
Is there any suggestion for it?