修改index.php,加上‘rowOptions’属性,实现回调的方法
下面的例子实现了:如果这行的branch_status 属性的值是inactive显示的背景是粉红色否则显示绿色
= GridView ::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' =>function( $model){
if($model-> branch_status=='inactive' ){
return [ 'class'=>'danger' ];
}else{
return [ 'class'=>'success' ];
}
},
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' =>'companies_company_id',
'value' =>'companiesCompany.company_name',
],
//'companiesCompany.company_name',
//'companies_company_id',
'branch_name' ,
'branch_address' ,
'branch_created_date' ,
'branch_status' ,
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
来自于datou:https://github.com/datou-leo/ci