I am using the YII Gridview want to show/hide columns when filtering the records Ex: If Name, City, State and phone is listing, I want checkbox to show/hide any of columns like Phone, Name in listing. Please suggest.
Thanks in advance
I am using the YII Gridview want to show/hide columns when filtering the records Ex: If Name, City, State and phone is listing, I want checkbox to show/hide any of columns like Phone, Name in listing. Please suggest.
Thanks in advance
you can use the visible attribute of gridview column fields
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'your_attribute1',
....
[
'label' => 'your_labe',
'attribute_n' => 'your_attribute',
'visible' => ( $your_condition == 'value_for_visible')
],
......
You have to use 'visible' option for that. just pass the condition in which condition you need to visible that column. Like This :
<?php echo GridView::widget( [
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute'=>'your_column',
'visible'=> if ( $data->field_name == "some_value" ) ? true : false,
'value'=>function( $data ) {
return !empty( $data->your_column ) ? $data->your_column : '0.5';
},
]
] );?>