O
O
Oversec2016-10-10 13:34:10
Yii
Oversec, 2016-10-10 13:34:10

How to filter by sum of two columns in gridview?

It is necessary that the GridView filter by the sum of two values. I display in GridView

[
                'attribute' => 'sum_goods',
                'label' => 'Сумма за товар',
                'value' => function ($model) {
                    return number_format($model->sum_goods + $model->sum_user_transport, 2, '.', ' ');
                }
            ],

How to set up a filter?
Tried to add conditions andWhere - does not help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-10
@Oversec

not in this implementation. Yii2 sorts at the SQL level. Accordingly, for sorting, you need to form the specified field using aggregate functions in the request for obtaining data, and only then sort by it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question