How can I reverse the order of CGridView (showing newest on top by default)?
I currently have the Gii generated code:
public function actionAdmin() {
$model = new Post('search');
$model->unsetAttributes();
if (isset($_GET['Post']))
$model->attributes = $_GET['Post'];
$this->render('admin', array(
'model' => $model,
));
Please help. Thanks.
You can try the corresponding class Post (in protected/models/Post.php) and find the search function. This is where the search area's content is controlled.
Try this:
Or refer to: http://www.yiiframework.com/doc/api/1.1/CDbCriteria
If you set the order as part of the query you won't be able to use the column sorters. You need to update the sort property where the data provider gets created, which in this case is probably in the function @xiaohan2012 mentioned. It would look something like:
OR to create a totally custom sort, you would need to create a new sort object something like:
in which case, your data provider would look something like: