jahau
(Jahau)
July 19, 2017, 8:00am
1
I want to hide certain columns when the GridView is sorted by some other column than the default one. For this I need to know the following things:
How to achieve this? Thanks.
[size="2"]Since sorting is done via GET request you can just get the sorted param.[/size]
[size="2"]Get the current sorted option (if multiSort is not enabled):[/size]
$currentSort = Yii::$app->request->queryParams['sort'];
Yii\data\Sort Sort param
Make a grid column conditionally visible:
[
'attribute' => 'name',
'visible' => ($currentSort === '-name' ? true : false
],
yii\gird\Column visible
jahau
(Jahau)
July 21, 2017, 12:36pm
3
Thanks, got it! I’m using Pjax and it’s a bit question mark to me where the get-variables should be checked? In the beginning of index-file or somewhere else?