Ok , this shouldn’t be complicated , but I haven’t seen anyone providing it:
For one model I’m displaying 2 same CgridViews in different places. In one place I want one column to be sorted by default , and in the other place another column.
Now , I could add sort defaultOrder in the model , but than it’ll sorf both the grids in the same way.
What if for the second place where you want to sort it according to some order, you use a query from the same model, sort according to whatever way you want, then display the returned data in a gridview.
You will have two gridviews, but the first one, will have the model as the data provider, and the second will use a query as a data provider.
Sql queries have an Order By command which lets you select a column by which to sort the records with.
Let say i have a table called staff, with a column age, then in Yii, using the query builder, you would sort the staff according to age, with a query like this one.