In order to sort Yii CSqlDataProvider you have to pass CSort() object to it.
1 2 3 4 5 6 7 8 9 10 11 |
$sort = new CSort(); $sort->attributes = array( 'id' => array( 'asc' => 'table.id', 'desc' => 'table.id DESC' ), 'value1' => array( 'asc' => 'table.value1', 'desc' => 'table.value1 DESC' ) ); |
In case the CSqlDataProvider is not sorted you should probably check your query passed to the object. Pay attention not to add a semicolon at the end of your query.
1 2 3 4 5 6 7 8 9 |
$query = "SELECT * FROM table1"; $dataProvider = new CSqlDataProvider($query, array( 'totalItemCount'=> $count1, 'sort' => $sort, 'params' => array(), 'pagination' => array( 'pageSize'=> 300 ) )); |
![Share on Facebook Facebook](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/facebook.png)
![Share on Twitter twitter](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/twitter.png)
![Share on Reddit reddit](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/reddit.png)
![Pin it with Pinterest pinterest](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/pinterest.png)
![Share on Linkedin linkedin](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/linkedin.png)
![Share by email mail](https://ictknowledge.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/96x96/mail.png)