Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable and disable sort in Yii2 GridView?

How to enable and disable sort in Yii2 GridView ?

Example

like image 492
rdanusha Avatar asked Dec 13 '14 21:12

rdanusha


1 Answers

You can customize columns sort in your DataProvider. For example if you use ActiveDataProvider in your GridView you can indicate sort-able columns like below:

$dataProvider = new ActiveDataProvider([     'query' => Model::find(),     'sort' => ['attributes' => ['column1','column2']] ]); 

In above example, only column1 and column2 are sort-able.

You can also disable sorting for all columns like below:

'sort' =>false 

It is suggested to take a look at Yii2's official document : Class yii\data\Sort As it defines it:

Sort represents information relevant to sorting. When data needs to be sorted according to one or several attributes, we can use Sort to represent the sorting information and generate appropriate hyperlinks that can lead to sort actions.

like image 193
Ali MasudianPour Avatar answered Sep 28 '22 22:09

Ali MasudianPour