In the grid the sorting work on first click only but next click nothing … it should each click sort content as ASC/DESC …
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,true);
$criteria->compare('cid',$this->cid);
$criteria->compare('title',$this->title,true);
$criteria->compare('uid',$this->uid);
$criteria->compare('status',$this->status);
$criteria->compare('created',$this->created);
$criteria->compare('changed',$this->changed);
$criteria->compare('promote',$this->promote);
$criteria->compare('sticky',$this->sticky);
$criteria->compare('main_image',$this->main_image);
$criteria->compare('slider_image',$this->slider_image);
if(!Yii::app()->request->getParam('sort')) $criteria->order = 't.id DESC';
else $criteria->order = Yii::app()->request->getParam('sort');
$sort = new CSort();
$sort->attributes = array(
'*',
'defaultOrder'=>array('id'=>CSort::SORT_ASC),
't.id'=>array(
'asc'=>'t.id',
'desc'=>'t.id desc',
),
'title'=>array(
'asc'=>'title',
'desc'=>'title desc',
),
'created'=>array(
'asc'=>'created',
'desc'=>'created desc',
),
);
View …
$this->widget('bootstrap.widgets.TbJsonGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'type' => 'striped bordered condensed ',
'summaryText' => false,
'cacheTTL' => 10, // cache will be stored 10 seconds (see cacheTTLType)
'cacheTTLType' => 's', // type can be of seconds, minutes or hours
'json' => true,
'enableSorting'=>true,
'ajaxUpdate'=>true,
'ajaxUrl'=>Yii::app()->createUrl( 'article/admin' ), // this takes care of the search
'columns' => array(
array(
'header'=>'id',
'name'=>'id',
'htmlOptions'=>array('width'=>'60'),
'headerHtmlOptions'=>array('width'=>'40')
),
array(
'header'=>'title',
'name'=>'title',
'htmlOptions'=>array('width'=>'420'),
'headerHtmlOptions'=>array('width'=>'120')
),
array (
'header'=>'category',
'name'=>'category',
'value'=>'$data->category->name',
'htmlOptions'=>array('width'=>'120'),
'headerHtmlOptions'=>array('width'=>'120')
),
array(
'header'=>'created,
'name' => 'created',
'type' => 'datetime',
'htmlOptions'=>array('width'=>'120'),
'headerHtmlOptions'=>array('width'=>'120')
),
array(
'header' => 'edit',
'class' => 'bootstrap.widgets.TbJsonButtonColumn',
'template' => '{view} {delete}',
/* 'deleteConfirmation'=>Yii::t('ui','Are you sure to delete this item?!?!??'), */
),
),
));