search is not working , in yii2 gridview -
i installed yii2 export menu.it working fine search not working properly.i cant understand whats going wrong? please fix it... here code-
<?php $gridcolumns = [ [ 'class' => 'yii\grid\serialcolumn', ], 'name', 'company_mail', 'created', 'modified', 'modified_by_id', ['class' => 'yii\grid\actioncolumn', 'urlcreator'=>function(){return '#';}], ]; ?> <?php echo exportmenu::widget([ 'dataprovider' => $dataprovider, 'filtermodel'=>$searchmodel, 'columns' => $gridcolumns, 'target' => exportmenu::target_blank, ]); ?> <?php echo gridview::widget([ 'dataprovider' => $dataprovider, 'filtermodel' => $searchmodel, 'columns' => $gridcolumns, ]); ?>
add following function search model
public function search($params) { $query = yourmodel::find(); $dataprovider = new activedataprovider([ 'query' => $query, 'sort' => [ 'defaultorder' => [ ] ], ]); $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(['like', 'name', $this->name]) ->andfilterwhere(['like', 'company_mail', $this->company_mail]) ->andfilterwhere(['like', 'modified', $this->modified]) ->andfilterwhere(['like', 'created', $this->created]) ->andfilterwhere(['like', 'modified_by_id', $this->modified_by_id]); return $dataprovider; }
Comments
Post a Comment