When I select an element from select2, it does nothing.
Here is the code for _columns and index:
Columns.php:
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use app\models\Mjg_aux_tipo_configuracion;
use kartik\grid\DataColumn;
use kartik\grid\ActionColumn;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use kartik\date\DatePicker;
use yii\app;
[
//'class' => ActionColumn::className(),
'class' => 'kartik\grid\ActionColumn',
'template' => '{view} {update} {delete}' ,
'dropdown' => false,
'vAlign'=>'middle',
'urlCreator' => function ($action, $model, $key, $index) {
return Url::to([$action, 'idtipoconfiguracion' => $key]);
},
'viewOptions'=>['role'=>'modal-remote','title'=>'Ver tipo de configuración','data-toggle'=>'tooltip'],
'updateOptions'=>['role'=>'modal-remote','title'=>'Actualizar tipo de configuración', 'data-toggle'=>'tooltip'],
'deleteOptions'=>['role'=>'modal-remote','title'=>'Borrar tipo de configuración',
'data-confirm'=>false, 'data-method'=>false,// for overide yii data api
'data-request-method'=>'post',
'data-toggle'=>'tooltip',
'data-confirm-title'=>'Eliminar Registro?',
'data-confirm-message'=>'Esta usted seguro de eliminar este registro?'],
],
];
INDEX.PHP:
<?php
use app\models\Mjg_aux_tipo_configuracion;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use kartik\grid\GridView;
use yii\bootstrap5\Modal;
use yii\helpers\ArrayHelper;
use yii\web\View;
use johnitvn\ajaxcrud\CrudAsset;
use johnitvn\ajaxcrud\BulkButtonWidget;
use yii\widgets\ActiveForm;
/ @var $this yii\web\View /
use yii\web\JqueryAsset;
use yii\widgets\Pjax;
/ @var yii\web\View $this */
/* @var app\models\Mjg_aux_tipo_configuracionSearch $searchModel /
/ @var yii\data\ActiveDataProvider $dataProvider */
CrudAsset::register($this);
$this->title = 'Tipos de Configuración';
$this->params['breadcrumbs'][] = $this->title;
registerJs(
"$('#ajaxCrudModal').on('hidden.bs.modal', function() {
location.reload();
})"
);
?>
"ajaxCrudModal",
'options' => [
'tabindex' => false // important for Select2 to work properly
],
'size' => Modal::SIZE_LARGE,
'clientOptions' => [
'backdrop' => 'static'
],
"footer"=>"",// always need it for jquery plugin
])?>
Could it be that it doesn't load the js and css files correctly? How do I do then?
Here is a screenshot of what it looks like:
![pantalla1](https://github.com/kartik-v/yii2-widget-select2/assets/70907885/5ad04c00-2584-4b23-9fc1-621f17b35ef0)
console screenshot:
![image](https://github.com/kartik-v/yii2-widget-select2/assets/70907885/0320491f-b04f-4a3a-9b62-e4c99fd07db5)
Since you are rendering by PJAX - the plugin needs to be reinitialized whenever there is pjax refresh. All Krajee widgets including Select2 provide a configuration option called pjaxContainerId. Read about it in the code here.
You need to set pjaxContainerId to the id matching your pjax container. So you must also in your code above set:
When I select an element from select2, it does nothing.
Here is the code for _columns and index:
Columns.php: <?php use yii\helpers\Url; use yii\helpers\Html; use app\models\Mjg_aux_tipo_configuracion; use kartik\grid\DataColumn; use kartik\grid\ActionColumn; use kartik\grid\GridView; use yii\helpers\ArrayHelper; use kartik\date\DatePicker; use yii\app;
date_default_timezone_set('America/Argentina/Buenos_Aires');
return [ / [ 'class' => 'kartik\grid\CheckboxColumn', 'width' => '20px', ],/
[
//'class' => ActionColumn::className(), 'class' => 'kartik\grid\ActionColumn', 'template' => '{view} {update} {delete}' , 'dropdown' => false,
'vAlign'=>'middle',
'urlCreator' => function ($action, $model, $key, $index) { return Url::to([$action, 'idtipoconfiguracion' => $key]); }, 'viewOptions'=>['role'=>'modal-remote','title'=>'Ver tipo de configuración','data-toggle'=>'tooltip'], 'updateOptions'=>['role'=>'modal-remote','title'=>'Actualizar tipo de configuración', 'data-toggle'=>'tooltip'], 'deleteOptions'=>['role'=>'modal-remote','title'=>'Borrar tipo de configuración', 'data-confirm'=>false, 'data-method'=>false,// for overide yii data api 'data-request-method'=>'post', 'data-toggle'=>'tooltip', 'data-confirm-title'=>'Eliminar Registro?', 'data-confirm-message'=>'Esta usted seguro de eliminar este registro?'], ],
];
INDEX.PHP: <?php
use app\models\Mjg_aux_tipo_configuracion; use yii\helpers\Html; use yii\helpers\Url; use yii\grid\ActionColumn; use kartik\grid\GridView; use yii\bootstrap5\Modal; use yii\helpers\ArrayHelper; use yii\web\View; use johnitvn\ajaxcrud\CrudAsset; use johnitvn\ajaxcrud\BulkButtonWidget; use yii\widgets\ActiveForm; / @var $this yii\web\View / use yii\web\JqueryAsset; use yii\widgets\Pjax; / @var yii\web\View $this */ /* @var app\models\Mjg_aux_tipo_configuracionSearch $searchModel / / @var yii\data\ActiveDataProvider $dataProvider */
CrudAsset::register($this); $this->title = 'Tipos de Configuración'; $this->params['breadcrumbs'][] = $this->title;
?>
<?php $form = ActiveForm::begin(); ?>
= Html::encode($this->title) ?>
Since you are rendering by PJAX - the plugin needs to be reinitialized whenever there is pjax refresh. All Krajee widgets including Select2 provide a configuration option called
pjaxContainerId
. Read about it in the code here.You need to set
pjaxContainerId
to the id matching your pjax container. So you must also in your code above set: