Filter search and pjax not working in yii2 gridview -
i used crud generator in yii2 generate codes, want make sorting, filter search , pjax working on gridview, sorting working perfectly, filter search , pjax not working.. below code.. controller.. actionindex
$searchmodel = new productsearch(); $dataprovider = $searchmodel->search(yii::$app->request->queryparams); return $this->render('index', [ 'searchmodel' => $searchmodel, 'dataprovider' => $dataprovider,
my view file index.php
<?php echo $this->render('_search', ['model' => $searchmodel]); ?> <?php pjax::begin(); ?> <?= gridview::widget([ 'dataprovider' => $dataprovider, 'filtermodel' => $searchmodel, 'pager' => [ 'firstpagelabel' => 'first', 'lastpagelabel' => 'last', 'prevpagelabel' => '<span class="glyphicon glyphicon-chevron-left"></span>', 'nextpagelabel' => '<span class="glyphicon glyphicon-chevron-right"></span>', 'maxbuttoncount' => 5, // customzing css class navigating link 'prevpagecssclass' => 'mypre', 'nextpagecssclass' => 'mynext', 'firstpagecssclass' => 'myfirst', 'lastpagecssclass' => 'mylast', ], 'columns' => [ ['class' => 'yii\grid\serialcolumn'], // 'product_id', 'type_name', 'name', 'descr', 'price', [ 'attribute'=>'image', 'label'=>'image', 'format'=>'html', 'value' => function ($data) { $url = $data['image']; $alt = $data['name']; return html::img($url, ['alt'=>$alt,'title'=>$alt,'width'=>'70','height'=>'50' ]); } ], // 'added_at',' // 'updated_at', 'views', 'status', // 'reviews', ['class' => 'yii\grid\actioncolumn'], ], 'tableoptions' =>['class' => 'table table-striped table-bordered'], ]); ?> <?php pjax::end(); ?>
if render _search.php file in index page in below code search working not working in filtersearch
<?php echo $this->render('_search', ['model' => $searchmodel]); ?>
below search models
public function search($params) { $query = products::find(); $dataprovider = new activedataprovider([ 'query' => $query, 'pagination'=> ['defaultpagesize' => 5], ]); $this->load($params); if (!$this->validate()) { // uncomment following line if not want return records when validation fails // $query->where('0=1'); return $dataprovider; } $query->andfilterwhere([ 'product_id' => $this->product_id, 'type_id' => $this->type_id, 'status' => $this->status, 'price' => $this->price, 'added_at' => $this->added_at, 'updated_at' => $this->updated_at, 'views' => $this->views, ]); $query->andfilterwhere(['like', 'type_name', $this->type_name]) ->andfilterwhere(['like', 'name', $this->name]) ->andfilterwhere(['like', 'descr', $this->descr]) ->andfilterwhere(['like', 'image', $this->image]) ->andfilterwhere(['like', 'reviews', $this->reviews]); return $dataprovider;
any on how make filtersearch work , make pjax work correcly.. thanks
Comments
Post a Comment