I want to hide yii2 gridview empty column if value is null but my code is not working.
I have tried this code:
[
'attribute'=>'division',
'value'=>'divisionName.name',
'visible' => function ($data) {
if ('divisionName.name' == NULL) {
return '0'; // or return true;
} else {
return '1'; // or return false;
}
},
]
And then tried this:
[
'attribute'=>'division',
'value'=>'divisionName.name',
'visible' => function ($data) {
if ('divisionName.name' == NULL) {
return true;
} else {
return false;
}
},
]
Above both line of codes not working.
If divisionName.name equal to null then hide entire column from gridview, what is wrong with this code?
答案 0 :(得分:1)
Seems you have also a logical problem because you would show a null value and hide a not null value ..
The right solution is based on an check for the hide/show condition before the widget is showed
$showDivision = myFunctioForShow(...);
[
'attribute'=>'division',
.....
'visible' => $showDivision ,
] ,