php - how to change grid view through Ajax? yii2 -


first of working yii2.0 framework.

right, have gridview pulls data database. works , if use of searches reload page new data.

however have created dropdownlist categories. there 3 tiers of categories , main category subcategory , child category. @ moment have 2 ajax requests populate sub , child category when dropdownlist changes. (it populates categories database).

now want gridview display cases linked child categories. when choose first category choose second , child category gridview displays content relates it.

at moment controller renders searchmodel + dataprovider grid view as seen below::

public function actionindex() {     $searchmodel = new casesearch();       $allcategory = category::find()->all();      $dataprovider = $searchmodel->search(yii::$app->request->queryparams);      return $this->render('index', [         'searchmodel' => $searchmodel,         'dataprovider' => $dataprovider,         'allcategory' => $allcategory     ]); } 

and in view displays data this::

<?= gridview::widget([     'dataprovider' => $dataprovider,     'filtermodel' => $searchmodel,     'columns' => [         'case_id',         'name',         'judgement_date',         'year',         ['class' => 'yii\grid\actioncolumn'],     ], ]); ?> 

how should go achieving this? should create _grid.php can render view , send ajax request there?

the simplest way achieve functionality wrap gridview built-in pjax widget so:

use yii\widgets\pjax;  <?php pjax::begin(); ?>  // place gridview code here  <?php pjax::end(); ?> 

from js can trigger form submit that:

$('.grid-view-selector').yiigridview('applyfilter'); 

if pjax attached, content replaced dynamically without page reload.

official docs:


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -