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:
- Food (priority_order 1)
- food_item1 (priority_order 1)
- fodd_item2 (priority_order 2)
- fodd_item3 (priority_order 3)
- Drink (priority_order 2)
- drink_item1 (priority_order 1)
- drink_item2 (priority_order 2)
- drink_item3 (priority_order 3)
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.