I have table of providers (id, title, onoff) where onoff column is a status: 1 = on, 0 = off I dont have table in DB for these statuses, so I don't have model for statuses.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'provider-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'id',
'htmlOptions'=>array('width'=>'40px'),
),
'title',
array(
'name'=>'onoff',
'filter'=>CHtml::dropDownList('Provider[onoff]', '',
array(
''=>'All',
'1'=>'On',
'0'=>'Off',
)
),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}{delete}'
),
),
It filters data, but after ajax forget the state of dropdown What is the best way to build dropdown in this case?
And what is the best way to substitute 1 to On and 0 to Off in datagrid cells?
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'provider-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'id',
'htmlOptions'=>array('width'=>'40px'),
),
'title',
array(
'name'=>'onoff',
'value'=>'Crud::getOnoff($data->onoff)',
'filter'=>CHtml::listData(Crud::getOnoffs(), 'id', 'title'),,
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}{delete}'
),
),
In model
public function getOnoffs()
{
return array(
array('id'=>'1', 'title'=>'On'),
array('id'=>'0', 'title'=>'Off'),
);
}
public function getOnoff($onoff)
{
if($onoff == 1)
return 'On';
else
return 'Off';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With