When displaying active records in a GridView you might encounter the case where you display values of related
columns such as the post's author's name instead of just his `id`.
columns such as the post author's name instead of just his `id`.
You do this by defining the attribute name in columns as `author.name` when the `Post` model
has a relation named `author` and the author model has an attribute `name`.
The GridView will then display the name of the author but sorting and filtering are not enabled by default.
...
...
@@ -482,13 +482,13 @@ class UserView extends ActiveRecord
}
```
After that you can youse this UserView active record with search models, without additional specifying of sorting and filtering attributes.
After that you can use this UserView active record with search models, without additional specifying of sorting and filtering attributes.
All attributes will be working out of the box. Note that this approach has several pros and cons:
- you dont need to specify different sorting and filtering conditions and other things. Everything works out of the box;
- it can be much faster because of data size, count of sql queries performed (for each relation you will need additional query);
- since this is a just simple mupping UI on sql view it lacks of some domain logic that is in your entities, so if you will have some methods like `isActive`,
`isDeleted` or other that will influence on UI you will need to duplicate them in this class too.
- you don't need to specify different sorting and filtering conditions and other things. Everything works out of the box;
- it can be much faster because of the data size, count of sql queries performed (for each relation you will need additional query);
- since this is just a simple mapping UI on sql view it lacks some domain logic that is in your entities, so if you have some methods like `isActive`,
`isDeleted` or other that will influence on UI, you will need to duplicate them in this class too.
### Multiple GridViews on one page
...
...
@@ -498,8 +498,8 @@ they do not interfere.
When using multiple instances of GridView you have to configure different parameter names for
the generated sort and pagination links so that each GridView has its individual sorting and pagination.
You do so by setting the [[yii\data\Sort::sortParam|sortParam]] and [[yii\data\Pagination::pageParam|pageParam]]
of the dataProviders [[yii\data\BaseDataProvider::$sort|sort]] and [[yii\data\BaseDataProvider::$pagination|pagination]]
instance.
of the dataProvider's [[yii\data\BaseDataProvider::$sort|sort]] and [[yii\data\BaseDataProvider::$pagination|pagination]]
instances.
Assume we want to list `Post` and `User` models for which we have already prepared two data providers