Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3cdf95d5
Commit
3cdf95d5
authored
Apr 11, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update data-grid.md
parent
5985896c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
5 deletions
+34
-5
data-grid.md
docs/guide/data-grid.md
+34
-5
No files found.
docs/guide/data-grid.md
View file @
3cdf95d5
...
...
@@ -191,10 +191,6 @@ Sorting data
Filtering data
--------------
-
https://github.com/yiisoft/yii2/issues/1581
TBD
For filtering data the GridView needs a
[
model
](
model.md
)
that takes the input from the filtering
form and adjusts the query of the dataprovider to respect the search criteria.
A common practice when using
[
active records
](
active-record.md
)
is to create a search Model class
...
...
@@ -253,7 +249,40 @@ class PostSearch extends Post
```
Filtering by related columns
You can use this function in the controller to get the dataProvider for the GridView:
```
php
$searchModel
=
new
PostSearch
();
$dataProvider
=
$searchModel
->
search
(
$_GET
);
return
$this
->
render
(
'myview'
,
[
'dataProvider'
=>
$dataProvider
,
'searchModel'
=>
$searchModel
,
]);
```
And in the view you then assign the
`$dataProvider`
and
`$searchModel`
to the GridView:
```
php
echo
GridView
::
widget
([
'dataProvider'
=>
$dataProvider
,
'filterModel'
=>
$searchModel
,
]);
```
Working with model relations
----------------------------
When displaying Active records in a GridView you might encounter the case where you display values of related
columns such as the posts authors 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.
You have to adjust the
`PostSearch`
model to add this functionallity.
TBD
-
https://github.com/yiisoft/yii2/issues/1581
-
https://github.com/yiisoft/yii2/issues/3013
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment