2017-09-13 11 views
0

指定された値より大きい列のグリッドビュー結果をフィルタリングする方法はありますか? グリッドビューに列の量があります。ユーザーが1000と検索すると、1000を超える量の結果がフィルタリングされます。これはどのように行うのですか? 私の検索モデルはこのようになりました。比較演算子を使用したYii2グリッドビューフィルタ

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; 
    } 
+0

'searchModel'でクエリを変更します。 –

+0

私に例を教えてもらえますか? – SaabzCoder

+0

入力した値より常に大きい値を比較したいですか? –

答えて

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]); 

あなたが検索結果に入力された金額を含めたい場合は、>=を使用しています。

+0

はい。これは正常に動作します。 – SaabzCoder

+0

もう一度質問してください。ユーザーが1000より大きい量を検索したいとし、1000未満の量または500と1000の間の量を検索したいとします。私はすべて同じ項目に対して>、<、の間でこれを行うことができますか? – SaabzCoder

+0

@sabithavargheseはい、できます。しかし、それはまた、必要な出力のタイプにも依存します。間には4つのオペランドが必要です。 –