Difference between #6 and #7 of
Searching and Sorting by Count of Related Items in CGridView

Revision #7 has been created by softark on Feb 17, 2015, 2:33:41 PM with the memo:

correct the indentation of the sample code
« previous (#6)

Changes

Title unchanged

Searching and Sorting by Count of Related Items in CGridView

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

CGridView, search, sort, filter, STAT, relation, count

Content changed

[...]
return new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 't.username',
    'attributes' => array(     ...      // order by     'post_count' => array(      'asc' => 'post_count ASC',     'desc' => 'post_count DESC',      ),     '*',      ),     ),     'pagination' => array(     'pageSize' => 20,     ),      ));
}
```
'attributes' section of sort configurations lets us overload default searching. This configuration says, that when user wants to sort by 'post_count' field it should be done like specified. The last entry '*' says that every other field of this model should be treated normally.
### CGridView
Now we have prepared everything for our grid:
[...]
21 0
40 followers
Viewed: 60 615 times
Version: 1.1
Category: How-tos
Written by: softark
Last updated by: softark
Created on: Mar 27, 2012
Last updated: 9 years ago
Update Article

Revisions

View all history