If you want to sort GridView by a specific column by default, the following code will do so.
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort'=>[
- 'defaultOrder'=>['attribute'=> SORT_DESC],
- ],
- ]);
Change ‘attribute’ to the name of the attribute to be sorted by.
Sort options are: SORT_DESC and SORT_ASC