Created
October 26, 2021 13:36
-
-
Save MasterHans/a340a420704b99d865b1113b5f1e07e5 to your computer and use it in GitHub Desktop.
Add filter in Backend to DataProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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