Hello, i noticed that using kartik\grid\GridView
with bootstrap5 I can't no more use filters on gridviews.
The page being created contains the following statement in a script:
(new bootstrap.Dropdown('#w1-button', {}));
but nothing exists with id="w1-button", so the script ends with a blocking exception and filtering no more works.
This is the view:
<?php
use app\models\Quiz;
use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\ActionColumn;
use kartik\grid\GridView;
use Yii;
/** @var yii\web\View $this */
/** @var app\models\QuizSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Quizzes';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="quiz-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Quiz', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
'IdQuiz',
'DtCreazione',
'DtInizioTest',
'DtFineTest',
'Esito',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, Quiz $model, $key, $index, $column) {
return Url::toRoute([$action, 'IdQuiz' => $model->IdQuiz]);
}
],
],
]); ?>
</div>
I resolved substituting row 103 of BootstrapWidgetTrait.php with the following statement:
$view->registerJs("if ($('#$id').length > 0) (new bootstrap.$name('#$id', $options));");
instead of
$view->registerJs("(new bootstrap.$name('#$id', $options));");
Additional info
| System | Version |
| ---------------- | ------------ |
| Yii version | 2.0 |
| PHP version | 8.1 |
| Operating system | Ubuntu 18.04 |