kartik Select2 FilterType in gridview doesn't work

1.4k views Asked by At

I have an issue about kartik select2 filterType that doesn't work , this is a portion of my code :

[
                    'format' => ['link',$idmodel],
                    'attribute' =>$attribute,
                    'filterType'=>GridView::FILTER_SELECT2,
                    'filterWidgetOptions' => [
                    'data' => \yii\helpers\ArrayHelper::map($model_::find()->all(),$attribute,'nom_'.strtolower($idmodel)),
                    'options' => ['placeholder' => '-'.$idmodel.'-'],
                    'pluginOptions' => ['allowClear' => true],
                    'theme' => Select2::THEME_KRAJEE,

                    ],  

When i comment this line :

'filterType'=>GridView::FILTER_SELECT2,

a text field appear in my filter grid view. Can any one help me ?? Thanks in advance

2

There are 2 answers

2
Tibor Nagy On

As I see it from your conversation with Edvin Tenovimas your problem is that no jQuery Javascript file is loaded. Did you installed the Select2 package normally with composer?

$ php composer.phar require kartik-v/yii2-widget-select2 "@dev"

In that case you have to see the file vendor/bower/jquery/dist/jquery.min.js. The file has to be copied into your assets directory under web/assets automatically. You could remove the content of the assets directories to force the creation of the assets again.

$ rm -rf web/assets/*
7
Gynteniuxas On

I believe by default GridView enables filtering unless you manually disable it. When you comment that out, it uses default text input instead of Select2. To also disable that one, use this on columns you want to disable filtering:

'filter' => false,