0

How to filter gridview results with a column greater than specified value? My gridview have a column amount. When user searches as 1000, i want to filter results as amount greater than 1000. How do i do this? Now my search model is like this.

public function search($params) {
            $query = Service::find();
            $dataProvider = new ActiveDataProvider([
                'query' => $query,
                'sort' => ['defaultOrder' => ['id' => SORT_DESC,
                    ]]
            ]);

            $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,
                'patient_id' => $this->patient_id,
                'service' => $this->service,
                'duty_type' => $this->duty_type,
                'staff_manager' => $this->staff_manager,
                'from_date' => $this->from_date,
                'to_date' => $this->to_date,
                'branch_id' => $this->branch_id,
                'status' => $this->status,
                'CB' => $this->CB,
                'UB' => $this->UB,
                'DOC' => $this->DOC,
                'DOU' => $this->DOU,
            ]);


            $query->andFilterWhere(['like', 'estimated_price', $this->estimated_price])
                    ->andFilterWhere(['like', 'amount', $this->amount])
                    ->andFilterWhere(['like', 'days', $this->days])
                    ->andFilterWhere(['like', 'service_id', $this->service_id]);

            return $dataProvider;
    }

1 Answers1

0
query->andFilterWhere(['like', 'estimated_price', $this->estimated_price])
     ->andFilterWhere(['>', 'amount', $this->amount])
     ->andFilterWhere(['like', 'days', $this->days])
     ->andFilterWhere(['like', 'service_id', $this->service_id]);

If you want to include entered amount in search result, use >=.

Insane Skull
  • 9,220
  • 9
  • 44
  • 63
  • Shall i ask one more question. suppose the user want to search the amount greater than 1000 and also want to search amount less than 1000 or amount between 500 and 1000. Can i all do this by >,<,between for the same field? – SaabzCoder Sep 13 '17 at 05:18
  • @sabithavarghese yes, you can. But it also depends on type of output needed. Remember between requires four operands. – Insane Skull Sep 13 '17 at 05:37