A
A
AlexKuznec2016-10-05 16:48:45
Yii
AlexKuznec, 2016-10-05 16:48:45

Inside pjax 2 widgets, how to achieve update of only one of them?

I want to achieve dynamic display of tab content.
Each tab is a date, when you click on it, the corresponding records should be loaded from the database. Since there are a lot of tabs, I used a plugin to organize scrolling, something like the top of browsers. The tabs themselves are also formed through a query to the database (unique dates are selected from the records) and are links.
In short, there are 2 widgets inside pjax: a list of dates and a GridView.
Clicking on the first tabs gives the impression that everything is fine :) In most cases, the data is updated without a visible reload. But in the case of scrolling the strip with tabs, it turns out that it is updated every time - the first tabs are displayed, and then they scroll to the selected one (as it is written in js).
The question is how, by clicking on the link, to ensure that the widget itself with the links is not updated along the way?
Here is part of the code from the view:

// на основании выборки из базы в цикле формируется массив вкладок для виджета
$items[] = [
        'label' => $label,
        'url' => ['event/index', 'EventSearch[usertime]' => $date],
        'active' => $active,
    ];

<?php Pjax::begin() ?>

    <?= ScrollTabs::widget([    // вкладки с датами сверху
        'items' => $items,
    ]) ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
        ...
        ],
    ]); ?>

<?php Pjax::end(); ?>

And a controller action:
public function actionIndex()
    {
        $searchModel = new EventSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $pagination = (new \yii\db\Query()) // выдает список дат, когда у данного пользователя имеются записи; записи в дальнейшем группируются по дням
            ->select('CAST(usertime as DATE) as userdate')
            ->from('event')
            ->where(['user_id' => Yii::$app->user->id]) // залогиненный юзер
            ->distinct()
            ->orderBy('userdate DESC');

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'pagination' => $pagination,
        ]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-05
@qonand

you have ScrollTabs wrapped in Pjax, so it is updated, wrap only grid in pjax and, of course, you need to update only the pjax container when clicking on ScrollTabs

<?php Pjax::begin() ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
        ...
        ],
    ]); ?>

<?php Pjax::end(); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question