I have a Yii2 GridView with implemented sortable option (I used kotchuprik extension) which add one column with drag'n'drop ability. The problem is that I need to be able to sort rows when some filter id GridView is set. GridView have column "Machine ID" and sorting need to be done only with rows with the same "Machine ID", so how to display column with drag'n'drop ability only when some Machine ID is set by column filter??
1 Answers
0
votes
You could use the visible property of the column
Yii\grid\DataColumn has visible property. This attrribute accepts boolean values, but you can dynamically using an expression that boolean value. eg:
use Yii;
...
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'tipo',
['attribute' => 'your_attribute',
'label' => 'Your Label',
'visible' => isThisColumnVisible(),
],
http://www.yiiframework.com/doc-2.0/yii-grid-column.html#$visible-detail
You can check $searchModel->your_attribute or a equivalent functin that return boolean
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'tipo',
['attribute' => 'your_attribute',
'label' => 'Your Label',
'visible' => isset($searchModel->your_attribute) ,
],