In Yii2 we have GridView like this:
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'layout' => "{items}\n{summary}\n{pager}",
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'id',
'size',
'program' => [
'label' => 'Program',
'value' => function($data)
{
return Html::a($data->program, ($data->program), ['target' => '_blank']);
},
'format' => 'raw',
],
'version',
'platform',
'license',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Is it possible to do to hide/show column, if we click, for example on button "Hide platform", then for show "Show platform", or maybe checkbox.
I cannot understand how to do this, help me please
You can do something like this: - Name the column you want to handle, e.g. an ID
[
'class' => 'yii\grid\SerialColumn',
'options' => [ 'id' => 'serial-column' ],
'width' => '1%',
'vAlign' => 'middle',
'hAlign' => 'right',
]
Then you modify css to have that column disappeared at the beginning
#serial-column {display: none}
Then you apply js for a checkbox to make it appear:
jQuery('#some-chkbox').click(function(){ jQuery('#serial-column').toggle(); })
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