B
B
BATPYIIIKOB2018-06-14 09:51:39
Yii
BATPYIIIKOB, 2018-06-14 09:51:39

How to display GridView::widget without reloading the page depending on the selections in the ActiveForm field?

Good afternoon.
Faced the following problem:
5b220e2bf3ef5036442479.jpeg
There is a form for creating a batch of products ActiveForm. When choosing a product brand via AJAX, I generate a batch number:
view code

<?= $form->field($model, 'id_marka')
                            ->dropDownList(\app\models\Marka::find()
                                ->select(['title','id'])
                                ->indexBy('id')
                                ->column(),
                                [
                                    'prompt' => '',
                                    'onchange' => '$.post(
                                                  "'.Url::toRoute('part/num-part').'",
                                                  {id : $(this).val()},
                                                  function(data){
                                                      $(".part-number").val(data)
                                                  }
                                    )'
                                ]
                            )
                ?>

controller function code
public function actionNumPart()
    {
        if(Yii::$app->request->isAjax)
        {
            $id = (int)Yii::$app->request->post('id');
            $result = Part::getNumber($id);
        }
        return $result;
    }

There are no problems with this.
Faced the following: depending on the selected brand, I need to display the prepared data in the GridView::widget without reloading the page, that is, prepare the $dataProvider to update the data in the GridView.
Can you please tell me how to do the task correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-06-14
@qonand

use pjax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question