带有比较运算符的 Yii2 gridview 过滤器
Yii2 gridview filter with comparison operators
如何过滤列大于指定值的 gridview 结果?
我的 gridview 有一列数量。当用户搜索为 1000 时,我想过滤结果的数量大于 1000。我该怎么做?
现在我的搜索模型是这样的。
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;
}
query->andFilterWhere(['like', 'estimated_price', $this->estimated_price])
->andFilterWhere(['>', 'amount', $this->amount])
->andFilterWhere(['like', 'days', $this->days])
->andFilterWhere(['like', 'service_id', $this->service_id]);
如果要在搜索结果中包含输入的金额,请使用 >=
。
如何过滤列大于指定值的 gridview 结果? 我的 gridview 有一列数量。当用户搜索为 1000 时,我想过滤结果的数量大于 1000。我该怎么做? 现在我的搜索模型是这样的。
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;
}
query->andFilterWhere(['like', 'estimated_price', $this->estimated_price])
->andFilterWhere(['>', 'amount', $this->amount])
->andFilterWhere(['like', 'days', $this->days])
->andFilterWhere(['like', 'service_id', $this->service_id]);
如果要在搜索结果中包含输入的金额,请使用 >=
。