Skip to content

Instantly share code, notes, and snippets.

@MasterHans
Created October 26, 2021 13:36
Show Gist options
  • Save MasterHans/a340a420704b99d865b1113b5f1e07e5 to your computer and use it in GitHub Desktop.
Save MasterHans/a340a420704b99d865b1113b5f1e07e5 to your computer and use it in GitHub Desktop.
Add filter in Backend to DataProvider
other.country.controller.js:
c.possibleCountries = {
config: {},
filter: {
countryType: 0
},
data: [],
};
c.possibleCountries.filter.countryType = 2;
return referenceBookCountry.search(c.possibleCountries.filter)
ReferenceBookCountriesProvider:
public function search()
{
$this->prepareCriteria();
if($this->countryType) {
$this->criteria->addCondition('s_uzs = ' . $this->countryType);
}
$this->preparePagination();
$dataProvider = $this->buildDataProvider();
return $this->buildData($dataProvider);
}
CountriesController.php:
public function actionNewSearch()
{
$this->checkReadPermission('crudOprusys');
$engine = new ReferenceBookCountriesProvider('search', Yii::app()->user->getIdentity());
$engine->attributes = Yii::app()->request->getRestParams();
$engine->countryType = Yii::app()->request->getRestParams()['countryType'] ?? 0;
if ($engine->validate()) {
$result = $engine->search();
Response::send($result);
} else {
Response::sendValidationError($engine->getErrors());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment