Carraydataprovider Custom Filter And Custom Sort

hi there ,

here I have to use custom SQL command to take RATE of users ,




$sql="SET @rank=0";

$sql2 = "

SELECT @rank := @rank +1 AS rank, userId, result, testId,nameAndFam,ip,tryCount

FROM tbl_testlog, user

WHERE (

tbl_testlog.userId = user.id and  testId =".$tId." AND ip='".$ip."'

)

ORDER BY result DESC

";




Yii::app()->db->createCommand($sql)->execute();;

$command=Yii::app()->db->createCommand($sql2);

$topUsers=$command->queryAll();



and the pass the result to CArrayDataProvider


$arrayDataProvider=new CArrayDataProvider($topUsers, array(

and then to the dataGird menu …


 

$this->widget('zii.widgets.grid.CGridView', array(

'id'=>'test-grid',

'dataProvider'=>$arrayDataProvider ,



finally I want to sort and filter the column,

I used some code like :




     $arrayDataProvider=new CArrayDataProvider($topUsers, array(

		'id'=>'id',

		'keyField' => 'userId',

		'pagination'=>array(

			'pageSize'=>50,

		),

                'sort'=>$sort

                 

	));



but the sort just apply once …

I want custom sort link in top as like as default dataGridview …

thanks in advance .

You need to pass this code




$sort = new CSort();

$sort->attributes = array(

            'testAttribute'=>array(

                'asc'=>'dateA DESC',

                'desc'=>'dateA ASC',

            ),

);



to your dataProvider and please make sure you have also enable sorting true in your CgridView. I hope it will work for you.

thank you for your replay ,

I used that and used sorting TRUE but not work,


$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'test-grid',

	//'dataProvider'=>$model->searchT($tid),

         'dataProvider'=>$arrayDataProvider ,

        //

	'filter'=>$model,   

	'columns' => array( 

		array( 

                        'name'=>'id',

			'header' => 'رتبه',

			'type' => 'raw',

                        'htmlOptions'=>array('width'=>'20px'),

			'value' => 'CHtml::encode($data["rank"])',

                        'sortable'=>TRUE,

		),