Я присоединился к 2 таблицы на моей модели поиска сyii2 GridView фильтр на соответствующей колонке
$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'
]
]
]);
Я не уверен, как это сделать фильтрация для этих 2 столбцов. Вот что у меня есть
$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 $region_name;
public $published_name;
На моих gridview
2 столбцов появляются и я могу сортировать их, однако нет никакого поля ввода для фильтрации , как я могу отфильтровать это?
Любые правила валидации для этих атрибутов? – soju