gpt4 book ai didi

gridview - yii2 gridview过滤器在相关列上

转载 作者:行者123 更新时间:2023-12-04 05:27:54 26 4
gpt4 key购买 nike

我在我的模型搜索中加入了 2 个表

$query = Surveys::find()->select('surveys.*,regions.name AS region_name, published.description as published_name');
$query->joinWith(['region']);
$query->joinWith(['published0']);

我现在为 2 个额外的列添加了排序
$dataProvider->setSort([
'attributes' => [
'name',
'description',
'survey_type',
'published_name' => [
'asc' => ['published.description' => SORT_ASC],
'desc' => ['published.description' => SORT_DESC],
'label' => 'Published',
'default' => SORT_ASC
],
'region_name' => [
'asc' => ['regions.name' => SORT_ASC],
'desc' => ['regions.name' => SORT_DESC],
'label' => 'Region'
]
]
]);

我不确定如何对这两列进行过滤。以下是我所拥有的
 $query->andFilterWhere([
'survey_id' => $this->survey_id,
'published' => $this->published,
'date_added' => $this->date_added,
'total_length' => $this->total_length,
'region_id' => $this->region_id,
'shrink' => $this->shrink,
'country_id' => $this->country_id,
'region_name' => $this->region_name,
'published_name' => $this->published_name
]);

$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['like', 'guid', $this->guid])
->andFilterWhere(['like', 'year_acquired', $this->year_acquired])
->andFilterWhere(['like', 'year_processed', $this->year_processed])
->andFilterWhere(['like', 'survey_type', $this->survey_type])
->andFilterWhere(['like', 'processing_type', $this->processing_type])
->andFilterWhere(['like', 'center_point', $this->center_point])
->andFilterWhere(['like', 'regions.name', $this->region_name])
->andFilterWhere(['like', 'published.description', $this->published_name]);

我还在 Surveys 中包含了公共(public)变量。模型
 public $region_name;
public $published_name;

在我的 gridview出现 2 列,我可以对它们进行排序,但是没有用于过滤的输入框。我该如何过滤这个?

最佳答案

必须通过至少一个规则过滤变量。

尝试将此添加到您的搜索模型中:

rules()
{
return [
...
[['region_name', 'published_name'], 'string', 'max' => 255]
];
}

来自 docs :

When this property is set, the grid view will enable column-based filtering. Each data column by default will display a text field at the top that users can fill in to filter the data.

Note that in order to show an input field for filtering, a column must have its yii\grid\DataColumn::$attribute property set or have yii\grid\DataColumn::$filter set as the HTML code for the input field.

When this property is not set (null) the filtering feature is disabled.

关于gridview - yii2 gridview过滤器在相关列上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29797074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com