Display all if is null

In my Gridview I have setup one of the Filters to be based on another filter (dependent select). This works.

    'filter' => Html::activeDropDownList(
            ->where(["=", 'ExpenseCategoryId', $searchModel->ExpenseCategoryId])
            'prompt' => 'Select a Sub-Category',

but I’d like to be dependent only in the event a value is entered for $searchModel->ExpenseCategoryId, otherwise display all the options. Similar to s criteria of

=$searchModel->ExpenseCategoryId OR $searchModel->ExpenseCategoryId IS NULL

What would be the way to achieve this?

Use andFilterWhere() https://www.yiiframework.com/doc/api/2.0/yii-db-querytrait#andFilterWhere()-detail

1 Like


Thank you. That works beautifully. I didn’t realize there was where() vs andFiletrWhere().

Thank you for taking the time to help!