Search code examples
phpyii2yii2-grid

change combo filter into checkbox filter on yii2 grid view


i want to change the combo filter on yii2 gridview into multiple checkbox is it possible ?

here is my gridview with combo filter

<?= GridView::widget([
    'dataProvider' => $dataProvider2,
    'filterModel' => $searchModel,
    'columns' => [
        [
          'class' => 'yii\grid\SerialColumn',
        ],

        //'m_id',
        [
          'attribute'=>'ins_id',
          'format' => 'text',
          'filter' => ArrayHelper::map($data,'ins_id','ins_nama'),
          'value' => function($data){
                $ins = new Instansi();
                $nama = $ins->find()->where(['ins_id'=>$data->ins_id])->one();
                return $nama->ins_nama;
          },
        ],
        'm_kegiatan',
        'm_location',
        [
          'attribute'=>'m_sifat',
          'format' => 'text',
          'filter' => Array('baru' => 'Baru', 'lanjutan' => 'Lanjutan', 'rehab' => 'Rehab', 'perluasan' => 'Perluasan'),
          'label' => 'Baru',
        ],
        'm_volume',
        [
          'attribute'=>'m_biaya',
          'format' => 'text',
          'value' => function($data){
                return 'Rp. '.number_format($data->m_biaya,'0',',','.');
          },
        ],
        //'created_by',
        //'created_at',
        //'updated_by',
        //'updated_at',
        //'m_status',
    ],
]); ?>
<?php Pjax::end() ?>

in that code i use array helper for the dinamic combo filter and array for static combo filter and i want change some combo filter into multiple checkbox but i don't know what code i can use to modify the combo filter of yii2 gridview into multiple checkbox.


Solution

  • Last year I have this issue and solve this by this , 100% works !

    'filter' => Html::activeDropDownList($searchModel, 'user_id', ArrayHelper::map(User::find()->where('lvl>0')->asArray()->all(), 'id', 'name'),['class'=>'form-control','prompt' => 'Select Category','multiple' => true,]),