C
C
coderlex2016-03-16 18:26:35
Yii
coderlex, 2016-03-16 18:26:35

How to sort GridView by model relative attribute field?

This is how the GridView column is built:

[
  'attribute' => 'vocabulary_id',
  'format' => 'raw',
  'value' => function ($model) {
    return Html::a(
      Html::encode($model->vocabulary->name),
      ['vocabularies/update', 'id' => $model->vocabulary_id]
    );
  }
],

The problem is that sorting is actually done by the value of the dependent model ID (vocabulary_id), and not by the name of this dictionary, which is displayed in the cell.
Any thoughts on this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-03-17
@coderlex

All thoughts are here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question