/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Trigger::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'admit_date' => $this->admit_date, 'hn' => $this->hn, 'admit_count' => $this->admit_count]); $query->andFilterWhere(['like', 'disease', $this->disease])->andFilterWhere(['like', 'ae1', $this->ae1])->andFilterWhere(['like', 'ae2', $this->ae2])->andFilterWhere(['like', 'ae3', $this->ae3])->andFilterWhere(['like', 'level', $this->level])->andFilterWhere(['like', 'step', $this->step])->andFilterWhere(['like', 'error1', $this->error1])->andFilterWhere(['like', 'error2', $this->error2])->andFilterWhere(['like', 'step_error', $this->step_error]); return $dataProvider; }
<div class="box box-success"> <div class="box-header"> <h3 class="box-title"> Trigger List</h3> </div> <!-- /.box-header --> <div class="box-body"> <?php //$searchModel = new ModelSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); ?> <?php echo DataTables::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => 'วันที่ Admit', 'format' => 'raw', 'value' => 'admit_date', 'contentOptions' => ['style' => 'max-width: 60px;']], ['label' => 'HN', 'format' => 'raw', 'value' => 'hn', 'contentOptions' => ['style' => 'max-width: 100px;']], 'admit_count', ['attribute' => 'disease', 'filter' => \app\models\Trigger::itemsAlias('step_ae'), 'value' => function ($model) { return $model->diagName; }], 'level', ['attribute' => 'step', 'filter' => \app\models\Trigger::itemsAlias('step_ae'), 'value' => function ($model) { return $model->stepAeName; }], ['attribute' => 'step_error', 'filter' => \app\models\Trigger::itemsAlias('step_error'), 'value' => function ($model) { return $model->stepErrorName; }], ['class' => 'yii\\grid\\ActionColumn']], 'tableOptions' => ['class' => 'table table-striped table-bordered hover']]); ?> </div> </div> </div> </div> </div> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php
/** * Finds the Trigger model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Trigger the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Trigger::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }