A
A
Alexander Pantyukhov2016-09-30 12:47:15
Yii
Alexander Pantyukhov, 2016-09-30 12:47:15

GridView how to change the background-color of a row by some condition?

Good day and productive workflow to you comrades.
The question is simple, but my eyes have already blurred something on Friday. I use GridView like this

echo grid\GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'containerOptions' => ['style' => 'overflow: hidden;'], 
    'headerRowOptions' => ['class' => 'kartik-sheet-style'],
    'hover' => true,
    'floatHeader' => true,
    'id' => 'gridView',
    'pjax' => true, 
    'pjaxSettings'=>[
//        'options' => $this->registerJs("a()"),
    ],
    'summaryOptions' => ['id'=>'summary', 'name'=>'unchanged'],
    'persistResize' => false,
    'resizableColumns' => false,
    'export' => false
]);

Can anyone tell me how to conditionally highlight the entire line, i.e. change her background?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-09-30
@Paromon

To do this, you can change the HTML attributes of the row through the rowOptions property, like this:

echo grid\GridView::widget([
    'rowOptions' => function ($model, $key, $index, $grid) {
         return ['class' => 'red-color'];
     }
)]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question