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.
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.
Comments