GridView, Modifying the query in ActiveDataProvider from a column

I’ve got a column class that formats some data and provides some filter options.

To make it reusable and a simple drop in the column adds the filtering instead of it being replicated across any filter models that might need it.

Just want to see if anyone thinks this is a bad idea or can see any potential caveats?




class CustomColumn extends \yii\grid\DataColumn

{

    public $filter = [

        1 => 'Option 1',

        2 => 'Option 2',

        3 => 'Option 3'

    ];

    

    public function init()

    {

        parent::init();

        if (!empty($this->grid->filterModel->{$this->attribute})) {

            if ('1' === $this->grid->filterModel->{$this->attribute}) {

                $this->grid->dataProvider->query->andFilterWhere(...)

            } else if ('2' === $this->grid->filterModel->{$this->attribute}) {

                $this->grid->dataProvider->query->andFilterWhere(...)

            }

        }

    }

...

}