kartik-v / yii2-tabs-x

Extended bootstrap tabbed navigation widget for Yii 2.0 with various alignment and styling options.
Other
30 stars 17 forks source link

Gridview filter fails after renderAjax #77

Closed PokkersKarlis closed 2 years ago

PokkersKarlis commented 2 years ago

I am using kartik-v/yii2-tabs-x and want them render by AJAX so I created view with tabs where first tab loads as usual and next needed to be loaded by ajax. Tabs view:

 echo TabsX::widget([
        'enableStickyTabs' => true,
        'items' => [
            [
                'label' => 'label1',
                'encode' => false,
                'content' => $this->render('_view_data', ['model' => $model, 'model2' => $model2])
            ],
            [
                'label' => 'label2',
                'encode' => false,
                'content' => '',
                'linkOptions'=>['data-url'=>Url::to(['/controller/view-document-tab', 'id' => $model->id])],
                'showFooter' => false,
            ],
        ],
        'position' => TabsX::POS_ABOVE,
        'encodeLabels' => 'false',
    ])
    ?>

My controller method:

 public function actionViewDocumentTab($id)
        {
            $model = $this->findModel($id);
            $fileSearchModel = new DocumentSearch();
            $fileSearchModel->consignment_id = $model->id;
            $fileDataProvider = $fileSearchModel->search(Yii::$app->request->queryParams);
            return json_encode($this->renderAjax('_view_files', ['dataProvider' => $fileDataProvider, 'searchModel' => $fileSearchModel]));
        }

In _view_files.php I have gridView:

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions' => ['style' => 'border: 1px solid #ddd'],
        'columns' => [
            [
                'attribute' => 'id',
                'enableSorting' => false,
            ],
            [
                'attribute' => 'filename',
                'enableSorting' => false,
            ],
            [
                'class' => DataColumn::class,
                'attribute' => 'type',
                'value' => static function ($model) {
                    /** @var Document $model */
                    return Document::getType($model->type);
                },
                'filterType' => GridView::FILTER_SELECT2,
                'filter' => array('' => '-') + Document::getType(),
                'enableSorting' => false,
            ],
            [
                'class' => DataColumn::class,
                'attribute' => 'status',
                'value' => static function ($model) {
                    /** @var Document $model */
                    return Document::getStatus($model->status);
                },
                'filterType' => GridView::FILTER_SELECT2,
                'filter' => array('' => '-') + Document::getStatus(),
                'enableSorting' => false,
            ],
            [
                'class' => DataColumn::class,
                'attribute' => 'created_at',
                'enableSorting' => false,
            ],
        ],
    ]) ?>

When I open label2 tab, it is loaded by AJAX and gridView shows up, but problem is that only in column "filename" filter input is working and all other filter fields is like loading and don't show up. filter

And the errors in dev tools saying:

error

Can anyone help me with this issue?

Libraries

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.