/ Published in: PHP
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:
<code>
'followersCount'=>array(self::STAT,'GraphEdge','end','condition'=>'status=1'),
</code>
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.
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:
<code>
'followersCount'=>array(self::STAT,'GraphEdge','end','condition'=>'status=1'),
</code>
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//AT THE END OF YOUR MODEL SEARCH FUNCTION 'criteria'=>$criteria, 'pageSize' =>15, ), 'id', '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', ), 'page_title', ), ), ));