-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying related data in a gridview data column #802
Conversation
DataColumn uses ArrayHelper::getValue() which is now able to get related data via `relation.attribute` syntax. TODO: - [ ] Documentation
I actually wanted to avoid introducing this syntax because it will come with side effects and in most cases it can be easily implemented with explicit expression. For example for |
A common solution to the related attribute label "problem" is to define labels in the current class. For example:
So the label stuff should IMO be solved that way; Have Yii look for an attribute label for these "related notions" in the current class, and fall back on the one in the related class. That said, there's definately the issue of related attributes not being sortable or filterable by default though, in Yii1. This is a super common thing that people ask how to do, and if we can solve it in Yii2 it wold be awesome. |
@rawtaz Your proposed label resolution algorithm is something I want to avoid because it is a bit magical, error prone and may confuse users. Besides the sorting issue, there's also another tricky issue: filtering. So basically with the introduction of notation |
Current solution for displaying and sorting: echo \yii\grid\GridView::widget(array(
'dataProvider' => new \yii\data\ActiveDataProvider(array(
'query' => \app\models\Invoice::find()->join('LEFT OUTER JOIN', 'customer', 'customer.id = invoice.customerId'),
'sort' => array(
'attributes' => array(
'nr',
'customerId' => array(
'asc' => array('customer.name' => Sort::ASC),
'desc' => array('customer.name' => Sort::DESC),
),
// ...
)
)
)),
'columns' => array(
array(
'attribute' => 'nr',
'value' => function($data) { return empty($data->nr) ? '#'.$data->id : $data->nr; },
'format' => 'text',
),
array(
'attribute' => 'customerId',
'value' => function($data) { return $data->customer->name; },
),
// ...
),
)); |
Any decision about this one? |
Not yet, will try to work on that later. |
Hi, Is there any news about Sorting relations ? |
DataColumn uses ArrayHelper::getValue() which is now able to get related
data via
relation.attribute
syntax.This feature was available in yii 1.1. and should also be in 2.0 imo
TODO: