N
N
Nadia2020-08-14 10:31:29
JavaScript
Nadia, 2020-08-14 10:31:29

How to correctly navigate to a new page and load data during pagination?

hello, I have such a problem
, I have a search form in the gridview (which stores the model fields), this form had to be taken out, since this is required in the project, so the standard grid search is not used. When I find data for a certain field, I update the data in the grid (via pjax) taking into account these fields, but when I try to go to another page using pagination, then all the data is loaded again,
I can’t figure out what to do, it’s possible to intercept the transition event on another page and again send the necessary data for the search with
pjax, please tell me what to do. I will not refuse any help, thanks in advance here is my Action
code

$searchModel = new Logs();
        $params = Yii::$app->request->isPost? Yii::$app->request->post() : Yii::$app->request->queryParams;
        $dataProvider = $searchModel->search($params);

        if(Yii::$app->request->isAjax) {
            return $this->renderAjax('logs', [
                'searchModel' => $searchModel,
                'dataProvider' => $dataProvider,
            ]);
        }

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


view logs
$('#form-search-logs').on('beforeSubmit', function(e){
     e.preventDefault();
     e.stopImmediatePropagation();
     
    var data = $(this).serialize();
    $.pjax.reload({container : '#logs-pjax', url: '$url', type: 'POST', data: data});
        
    return false;
   });


the gridView itself is wrapped in Pjax
<?php Pjax::begin(['id' => 'logs-pjax', 'timeout' => false, 'enablePushState' => false]);?>
<?= GridView::widget([
 'id' => 'grid-logs',
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'options' => ['style' => ''],
    'columns' => [
...
    ]
]);
Pjax::end();


Search Form
<?php $form = ActiveForm::begin(['id' => 'form-search-logs']); ?>
            <div class="form-group" style="padding: 1%;">
                <div class="row">
                    <div class="col-md-3">
                        <?= $form->field($searchModel, 'id')->textInput() ?>
                    </div>
     ...
                </div>
                <div class="row">
                    <?= Html::submitInput(Yii::t('app', 'Search'), [
                        'class' => 'btn btn-success pull-right',
                        'style' => 'margin-right: 30px;'
                    ]) ?>
                </div>
            </div>
            <?php $form = ActiveForm::end(); ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question