V
V
VadimHoffman2015-04-21 03:41:07
Yii
VadimHoffman, 2015-04-21 03:41:07

Yii - how to filter and sort custom columns in cgridview?

Good afternoon!
I will give a hypothetical example. In CGridView I create a custom column:

array(
            'header'=>'Заголовок',
            'type'=>'raw',
            'value'=>'$data->id + 90',
        )

In general, value contains some random value. How to filter and sort columns with such values?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-04-21
@bIbI4k0

www.yiiframework.com/doc/api/1.1/CDataColumn#sorta...
The property sortable determines whether the grid view can be sorted according to this column. Note that the name should always be set if the column needs to be sortable. The name value will be used by CSort to render a clickable link in the header cell to trigger the sorting.
In a nutshell: you need to specify the model attribute in the name and set the CSort accordingly when forming the dataProvider so that the column is rendered in the table as sortable. But if you calculate the value at the presentation level, as in the example, then there is a chance to get the wrong order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question