How to sort a gridview field by this virtual attribute?

I’ve created a virtual attribute in my model




    public function getCountVencidas(){

        $titulo = new FinlegadoTitulo();

        $parcelas = $titulo->parcelasByClienteAndStatus($this->id,'A',true);

        return count($parcelas);

    }



and I need to sort a gridview by this attribute, the dataProvider is as follows:




        $dataProvider = new ActiveDataProvider([

            'query' => $query,

            'sort'  => ['defaultOrder' => ['countVencidas' => SORT_DESC]],

        ]);



but nothing happens.

I NEED HELP!

Hi!

This should help:

http://www.yiiframework.com/wiki/621/filter-sort-by-calculated-related-fields-in-gridview-yii-2-0/

Best Regards