When setting up the AJAX click to sort links for your index pages, it's nice to be able to sort on STAT and related data.
To get related data sorting in my CListView, I ended up having to forget about using "together" and "with" in my search function, and instead let everything lazy load. The number of queries explode, which sucks.
For handling your STAT relations, you can manually write SQL that runs when the sorting links are clicked. So this is pretty much duplicate code and sloppy, but it works.
The query below recreated this relation that exists on the model:
The naming here doesn't matter, the relation and sortable attribute are unfortunately independent. This was written for CListView but probably works with CGridView as well. Don't forget to add followers_count to your List View's sortable attributes array.
- //AT THE END OF YOUR MODEL SEARCH FUNCTION
- return new CActiveDataProvider($this, array(
- 'pagination' => array(
- 'pageSize' =>15,
- 'defaultOrder'=> array('id'=>CSort::SORT_ASC), //Can add more here, but arrows show
- 'desc' => '(SELECT SUM(graph_edge.id) FROM graph_edge WHERE graph_edge.end = t.id AND graph_edge.status = 1) DESC',
- 'asc' => '(SELECT count(graph_edge.id) FROM graph_edge WHERE graph_edge.end = t.id AND graph_edge.status = 1) ASC', //This query should match your STAT relationship
- 'desc' => 't.create_time DESC',
- 'asc' => 't.create_time ASC',
You need to login to post a comment.