yAnTar
yAnTar

Reputation: 4610

How add css class to CGridview cell (in Yii), related on another value

I have list of files. In array data provider i have fields: approved, filename, uploaded etc.

I want to add css class bold to cell filename, but with condition if approved == 1. This is part of my view

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $provider,
    'filter' => $model,
    'columns' =>
        array(
            array(
                'name' => 'file_name',
                'header' => 'Filename',
                'filter' => '',
                'htmlOptions' => array(
                    'class' => ($data['approved']) ? (1) : (0)
                ),
            ),

I can use $data['approved'] in value, but not in htmlOptions.

Upvotes: 3

Views: 11821

Answers (2)

channasmcs
channasmcs

Reputation: 1156

array(   'name'=>'Status',
           //'value'=>'$data->getYesNoText()',
           'filter' => '',
            'cssClassExpression' => '$data["Status"] == "Allocated" ? "Allocated" : ""',
            'cssClassExpression' => '$data["Status"] == "Pending" ? "Pending" : ""',
             // 'value' => '($data->Status !== "Allocated")?$data->bold($data->Status):$data->Status',
               ) ,

Upvotes: 0

jborch
jborch

Reputation: 1136

What you are looking for is http://www.yiiframework.com/doc/api/1.1/CGridColumn#cssClassExpression-detail

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $provider,
    'filter' => $model,
    'columns' =>
        array(
            array(
                'name' => 'file_name',
                'header' => 'Filename',
                'filter' => '',
                'cssClassExpression' => '$data["approved"] == 1 ? "bold" : ""',
            ),

Upvotes: 7

Related Questions