I am using CActiveDataprovider to show data from different tables. Now I am stuck with a problem. I have got two tables (items and categories) and they both have got priority_order columns and I need to show the data using order by both the columns.
For example: there are two categories and six items belonging to these categories:
Now I need to show the data in CGridView exactly as they are in above order. All the food items will come first and will be sorted by their priority_order and drink items will come later; obviously in their order.
In ItemsController
I am trying below code (for now order by categories only)
$dataProvider = new CActiveDataProvider('Items', array(
'criteria' => array(
'with' => array('category'),
'condition' => 'user_id=' . Yii::app()->user->id,
//'order' => 't.priority_order ASC',
'order' => 'category.priority_order ASC',
),
));
I would be happy to provide more details if still not clear enough. Any help would be appreciated.
$dataProvider = new CActiveDataProvider('Items', array(
'criteria' => array(
'with' => array('category'),
'condition' => 'user_id=' . Yii::app()->user->id,
'order' => 'category.priority_order ASC, t.priority_order ASC',
),
));
Giving a second param to the order criteria should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With