joinWith("staff"); // 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; } if ($this->staff_name) $query->andFilterWhere(['LIKE', 'name', $this->staff_name]); if ($this->staff_department) $query->andFilterWhere(['department_id' => $this->staff_department]); if ($this->staff_code) $query->andFilterWhere(['code' => $this->staff_code]); if ($this->card_number) $query->andFilterWhere(['logs.card_number' => $this->card_number]); // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'staff_id' => $this->staff_id, 'device_id' => $this->device_id, 'door_id' => $this->door_id, 'in_out_state' => $this->in_out_state, 'time' => $this->time, 'event_type' => $this->event_type, ]); return $dataProvider; } }