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
8881c0c6
Commit
8881c0c6
authored
Apr 11, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed wrong example.
parent
323937f2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
7 deletions
+4
-7
data-grid.md
docs/guide/data-grid.md
+4
-7
No files found.
docs/guide/data-grid.md
View file @
8881c0c6
...
...
@@ -275,14 +275,14 @@ 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 post
s author
s name instead of just his
`id`
.
columns such as the post
's 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.
You have to adjust the
`PostSearch`
model that has been introduced in the last section to add this functionallity.
To enable sorting on a related column you have to join the related table and add the sorting rule
to the Sort component of the dataprovider:
to the Sort component of the data
provider:
```
php
$query
=
Post
::
find
();
...
...
@@ -307,11 +307,8 @@ Filtering also needs the joinWith call as above. You also need to define the sea
```
php
public
function
attributes
()
{
// add related fields to searchable attributes when in search scenario
if
(
$this
->
getScenario
()
==
'search'
)
{
return
array_merge
(
parent
::
attributes
(),
[
'site.number'
]);
}
return
parent
::
attributes
();
// add related fields to searchable attributes
return
array_merge
(
parent
::
attributes
(),
[
'author.name'
]);
}
public
function
rules
()
...
...
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