Gridview trigger search with default param values

The question is in the title.

What is the best approach to trigger a search in a GridView with default params values.


  $searchModel = new MyModelFilter(['status'=> MyModel::STATUS_ACTIVE]);

  $dataProvoder = $searchModel->search(Yii::$app->request->getQueryParams());

First line will not trigger the search when using search filter generated by Gii. The main reason is that the form is not submitted hence $this->load($params) returns false in the below code ($params being empty).

if (!($this->load($params) && $this->validate())) {

     return $dataProvider;


So whould you do to have filter defaults values and triggering the search without user action (knowing that the user can modify the default value, eg: filtering the grid on a different status value).

For the record, I know I can modify the request query params to manually add the default value but, conceptually, I think it is better to modify the model filter instead of the user submitted params.

$searchFilter = new MyModelFilter;

$queryParams= Yii::$app->request->getQueryParams();

$queryParams['MyModelFilter']['status'] = MyModel::STATUS_ACTIVE;

$dataProvider = $searchFilter($queryParams);

No answer…

Is it that my question being not clear enough?

Or Is it that there is no other way than playing with the queryParams to set default values to a search Filter?

I don’t like writing code like this:

$agentQueryParams['UserFilter']['company_id'] = $model->id;

Any though on that matter would be interesting :)