Sort GridView by 'fake' attribute

Is there a way to sort a GridView by attribute that is not a field in the database but a custom-created getter function in the model?

e.x.


class SomeModel extends \yii\mongodb\ActiveRecord {

    ...

    public function getVal() {

        return rand(0, 10);

}



And then define sort in Data Provider




    ...

    $provider->sort->defaultOrder = ['val' => SORT_ASC];

doesn’t work