yiisoft/yii2-bootstrap5

kartik Gridview widget problem with bootstrap5

pzavoli71 opened this issue · 2 comments

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

@pzavoli71 problem in GridViewTrait::initLayout() is not optimized: method render widget, but not display.

https://github.com/kartik-v/yii2-grid/blob/6e02d25feeb19d8bab82354ea25dcdb9189c37c3/src/GridViewTrait.php#L1603

@pzavoli71

  '{toolbarContainer}' => $this->renderToolbarContainer(),
  '{toolbar}' => $this->renderToolbar(),

$this->renderToolbarContainer() call $this->renderToolbar() too i.e. method called twice, but may never displayed