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


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







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(


'dataProvider'=>$arrayDataProvider ,

finally I want to sort and filter the column,

I used some code like :

     $arrayDataProvider=new CArrayDataProvider($topUsers, array(


		'keyField' => 'userId',







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(


                '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(



         'dataProvider'=>$arrayDataProvider ,



	'columns' => array( 



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

			'type' => 'raw',


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