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?
'visible', only true or false is allowed. And this property is only evaluated once, it does not check for each row if there is a value or not and decides whether the column should be shown or not. And'divisionName.name' == NULLis false - you compare a string with NULL. Andif(...) return true; else return false;... don't you know that this is absolutely superfluous?