Not load kartik's select2 as filter in GridView. Yii2

Arturo Verbel De León

I try to filter a column using Select2 Kartik, but nothing appears. The select2 does not load completely. Show the display label as None.

/views/user/index.php

    'columns' => [
       [
           'class' => 'yii\grid\SerialColumn',
       ],
       'name',

    /*
       This code not works :(
    */

       [
           'attribute' => 'identification_type',
           'value'=> function($model){
               return Yii::t('app', TYPE_ID[$model->identification_type]);
           },
           'filter' => Select2::widget([
               'model' => $searchModel,
               'attribute' => 'identification_type',
               'data' => Arrai::t('person',TYPE_ID),
               'theme' => Select2::THEME_BOOTSTRAP,
               'hideSearch' => true,
               'options' => [
                   'placeholder' => Yii::t('person', 'Identification type'),
           ]),
       ],

    /*
       This code works!
    */

       [
           'attribute' => 'identification_type',
           'filter' => Arrai::t('app', TYPE_ID),
           'value'=> function($model){
                return Yii::t('app', TYPE_ID[$model->identification_type]);
            },
           'filterInputOptions' => [
                'class' => 'selectpicker',
                'data-style'=>"btn btn-primary btn-round",
                'title'=> "Sin seleccion",
           ],
        ],

    // other columns


]

And the following is the result html:

Result HTML

<div class="form-group is-empty">
<select id="personsearch-identification_type" class="form-control" name="PersonSearch[identification_type]" 
    data-s2-options="s2options_6cc131ae"
    data-krajee-select2="select2_0ed9734f"
    style="display:none">
       <option value="">Tipo de identificación</option>
       <option value="CC">Citizenship card</option>
       <option value="CE">Foreigner ID</option>
       <option value="PAS">Passport</option>
       <option value="NIT">NIT</option>
</select>
<span class="material-input"></span></div>

In this result, a <span> tag is required to display the Select2. But it does not appear.

Arturo Verbel De León

I found the problem What happens is that I had the advanced search enabled. And the select2 of the advanced search has the same ID as the GridView filter.

I just have to modify the ID name and it's ready.

[
    'attribute' => 'id_setting_person_identification_type',
    'value' => function($model){
        $type_identication = SettingPerson::getMapGroup('Tipo de identificación');
        return Yii::t('app', $type_identication[$model->id_setting_person_identification_type]);
    },
    'filterType' => GridView::FILTER_SELECT2,
    'filter' => $type_identication, 
    'filterWidgetOptions' => [
        'pluginOptions' => ['allowClear' => true],
    ],
    'filterInputOptions' => [
        'placeholder' => '-',
        'id' => 'id_setting_person_identification_type_gridview',
    ]
],

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Yii2 gridview filter by using autocomplete textbox

filter as you type in yii2 gridview

Yii2: Kartik Gridview sum of a column in footer

YII2 Kartik gridview disable pdf export

kartik GridView Yii2 - How To Configure the Export Configuration For PDFs (Header, Footer, Title)

Paging and Filter in Yii2 Gridview

Default Filter in GridView with Yii2

Yii2 field filter not showing on GridView

Yii2 Kartik GridView Word-Wrapping

How to use Yii2 kartik gridview editable column with mulitple model relations

Yii2 kartik GridView " The 'gridview' module MUST be setup in your Yii configuration "

GridView filter model in Yii2

yii2 gridview filter date

Yii2 : Add empty row at the top of the table using kartik\gridview

On yii2 kartik Gridview: Disable click to expand for a Select2 in a cell

Yii2 datepicker in kartik gridview not working

Yii2 kartik-v gridview: TypeError: jQuery(...).editable is not a function

Yii2 GridView filter date by year

Filter data with kartik Select2 widget in gridview

Kartik's yii2-grid: Setting unknown property: kartik\grid\GridView::panel

Yii2: Using TinyMCE into Kartik's DetailView with custom settings

Remove Dollar sign from Column value(Indian Currency) Yii2 kartik gridview

Yii2: Kartik's DetailView and Select2 loading id's not text

YII2 : kartik Select2

Yii2 export after filter gridview

PageSummary is not working in kartik GridView in yii2

Yii2 - Kartik/EditableColumn in GridView does not save the value

The Select/Unselect all are not working in Kartik select2 yii2

Yii2 Kartik-v gridView widget. How to pass # from 'formatUrl' to url