E
E
EVOSandru62017-09-07 12:35:12
Yii
EVOSandru6, 2017-09-07 12:35:12

How in Yii2 custom filter _search file using pjax so that ListView and GridView are updated without page reload?

Good afternoon,
There is a controller:

public function actionIndex()
    {
        $searchModel = new OffersSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

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

index.php :
<?php Pjax::begin(['id' => 'notes']) ?>
                            <?= GridView::widget([
                                'dataProvider' => $dataProvider,
                                'filterModel' => $searchModel,
                                'columns' => [
                                    ['class' => 'yii\grid\SerialColumn'],
                                    'id',
                                    'name',
                                    ['class' => 'yii\grid\ActionColumn'],
                                ],
                            ]); ?>
                        <?php Pjax::end() ?>

js :
$("#search_note").on("pjax:end", function() {
        $.pjax.reload({
            container:"#notes"
        });  
    });

_search.php file:
<?php yii\widgets\Pjax::begin(['id' => 'search_note']) ?>
        <?php $form = ActiveForm::begin([
            'options' => ['data-pjax' => true ],
            'method' => 'post',
        ]); ?>
...
        <?= $form->field($model, 'id')->textInput([
            'type'=>'number'
        ]) ?>
...

            <?= Html::submitButton(Yii::t('app', Yii::t('app','search')), ['class' => 'btn btn-primary']) ?>
            <?= Html::resetButton(Yii::t('app', Yii::t('app','reset')), ['class' => 'btn btn-default']) ?>
     
   <?php ActiveForm::end(); ?>

    <?php yii\widgets\Pjax::end() ?>

If I change to Then the filter works, but after reloading the page and all GET parameters fly to the address bar. I would like to send the data from the form as a post without reloading the page. Tell me what am I doing wrong? And another question, maybe someone knows - how to transfer the sort view in a custom form so that it can be eaten by dataProvider ? Relevant for ListView .
'method' => 'post',
'method' => 'get',

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-11
@EVOSandru6

https://nix-tips.ru/yii2-vnikaem-v-pjax.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question