yii - FIlter setup in GridView in YII2 -


hi have yii code in can able display data model search bar not comming in gridview, please help.

gridview code :

<?= gridview::widget([         'dataprovider' => $dataprovider,         'filtermodel' => $searchmodel,         'columns' => [             ['class' => 'yii\grid\serialcolumn'],             // 'emp_attendance_pid',             [                      'label' => 'employee id',                     'attribute' => 'emp_history_id',                     'value' => 'emp_history_id',             ],             [                   'label' => yii::t('app','first name'),                  // 'attribute' => 'emp_history_id',                   'value' => 'emphistory.emp_first_name',                 'filter' => arrayhelper::map(app\modules\employee\models\empinfo::find()->all(), 'emp_info_id', 'emp_first_name')             ],             [                   'label' => yii::t('app','last name'),                  // 'attribute' => 'emp_history_id',                   'value' => 'emphistory.emp_last_name',                 'filter' => arrayhelper::map(app\modules\employee\models\empinfo::find()->all(), 'emp_info_id', 'emp_last_name')             ], 

here can see filter, in able data using arrayhelper need data giving in search box, search box not coming, drop down comming

parameter attribute required filtering.

if define filter property, have dropdown list. understood, want text input, don't need filter.

if want search via related table, should create public properties in searchmodel , create validation rules. see example, want filter data related table;

here little example:

setup search model

 public $emp_first_name;   public function rules()   {     return [         [['emp_first_name'], 'safe']     ];  }   public function search($params)   {      $query = person::find()->joinwith(['emphistory'])->groupby(person::tablename().'.id');       $dataprovider = new activedataprovider([          'query' => $query,      ]);       if (!($this->load($params) && $this->validate())) {          return $dataprovider;      }       $query->andfilterwhere(['like', empinfo::tablename().'.emp_first_name', $this->emp_first_name]);       return $dataprovider; } 

in view:

<?= gridview::widget([     'dataprovider' => $dataprovider,     'filtermodel' => $searchmodel,     'columns' => [         ['class' => 'yii\grid\serialcolumn'],         'emp_history_id',         [             'attribute' => 'emp_first_name',             'value' => 'emphistory.emp_first_name',         ],         ['class' => 'yii\grid\actioncolumn'],     ] ]); ?> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -