Sort and filter data in GridView Yii2 where column is not in database

后端 未结 3 581
孤独总比滥情好
孤独总比滥情好 2020-12-28 23:38

If I have 2 fields in db - probability and influence and I need a column in GridView where these two fields are multiplied. I managed to add it there like:

          


        
3条回答
  •  攒了一身酷
    2020-12-29 00:00

    Removed

          $query->select('*, (probability * influence) as priority');
    

    changed

              'priority' => [
                    'asc' => ['(probability * influence)' => SORT_ASC],
                    'desc' => ['(probability * influence)' => SORT_DESC],
                    'label' => 'Priority',
                  ],
    

    and after $this->load($params);

              $query->andFilterWhere(['=', '(probability * influence)', $this->priority]);
    

    And search works as needed! :)

    Thanks for help!

提交回复
热议问题