3

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.

4

2 回答 2

7

您正在寻找的是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" : ""',
            ),
于 2012-11-01T14:39:17.027 回答
0
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',
               ) ,
于 2014-08-07T04:46:44.953 回答