I’m using Dynagrid from Kartik and I’m not being able to add a dropdown in the filter grid.
Right now every column has the text input but I want to replace for a dropdown list with the results inside the dropdown.
Any clue?
I’m using Dynagrid from Kartik and I’m not being able to add a dropdown in the filter grid.
Right now every column has the text input but I want to replace for a dropdown list with the results inside the dropdown.
Any clue?
Hi, dudunegrinhu. If I understood your question, the example below may help you to get an idea:
<?php
$noYes = [
['id' => '0', 'desc' => 'Não'],
['id' => '1', 'desc' => 'Sim'],
];
$columns = [
// .....
[
'attribute' => 'team_id',
'filter' => ArrayHelper::map(Team::find()->orderBy('name')->asArray()->all(), 'id', 'name'),
'value' => function($model) {
if ($rel = $model->getTeam()->one()) {
return yii\helpers\Html::a($rel->name,['team/view', 'id' => $rel->id,],["data-pjax"=>0]);
}
return '';
},
'format' => 'raw',
'contentOptions' => ['style'=>'width: 240px; text-align:left'],
],
// ....
[
'class' => '\kartik\grid\BooleanColumn',
'attribute' => 'ismanager',
'filter' => ArrayHelper::map($noYes, 'id', 'desc'),
'trueLabel' => 'Sim',
'falseLabel' => 'Não'
],
];
echo DynaGrid::widget([
'options'=>['id'=>'dynagrid-1'],
'columns' => $columns,
'gridOptions'=>[
'dataProvider'=>$dataProvider,
'filterModel'=>$searchModel,
// ....
],
]);
?>
Salute!