How 2 Way Sorting ?

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?!?!??'), */

		),

	),

	));




Hi

comments temporarly the below


 if(!Yii::app()->request->getParam('sort')) $criteria->order = 't.id DESC';

                        else $criteria->order = Yii::app()->request->getParam('sort');


 'cacheTTL' => 10, // cache will be stored 10 seconds (see cacheTTLType)

        'cacheTTLType' => 's', // type can be of seconds, minutes or hours

If the problem will be solved then we can focus on the above code.

Hello,

Same thing, when click on the header is sending "admin?sort=id&ajax=yw0", and its sending the same on the next click … I believe this wrong !

I think in the first request everything is ok, the second one something happening in javascript code, check also the console section in firebug…

From where is reading the link status & url?

in network section of firebug

that was from network section …

but I have bigger issue now :(

now when I click page number … or on table header … one column is disappear …why is that ?

I mean column value …

check what sending on the network (GET or POST) by clicking of the column

Also for debuging let one or two columns at once, comments the others.

Maybe you have a column(s) causing the problem

its also showing the commented columns …grhhh

the


    'defaultOrder'=>array('id'=>CSort::SORT_ASC),



Should’t be in the


                $sort->attributes = array(



its under $sort->attributes

My problem now columns value are disappearing onclick!

I found why the columns are disappearing … admin action have 2 views for static, and for ajax call …




	public function actionAdmin()

	{

		$model=new Article('search');

		$model->unsetAttributes();  

		if(isset($_GET['Article'])) $model->attributes=$_GET['Article'];

		if(isset($_GET['ajax'])) $this->renderPartial('_admin', array('model' => $model));

     		else $this->render('admin',array('model'=>$model,));

	}




any changes to make the both as one file, I had tried many ways with no result, any got same issue?

THX