Disable sorting in header column of Yii CGridView
Asked Answered
K

3

5

Yii provides sorting functionality for listing. How can I disable sorting so that my records will not get sorted when clicked on column header?

Kattie answered 1/10, 2012 at 6:34 Comment(0)
C
23

set 'enableSorting' => false in your list/gridview definition.

$this->widget('zii.widgets.CListView', array(
        ......
        'enableSorting' => false,
        ......
    )
);
Claman answered 1/10, 2012 at 6:43 Comment(0)
B
0

When Bootstrap is used you can disable sorting by using below syntax -

$this->widget('bootstrap.widgets.TbExtendedGridView',
  array(
         ......
         'enableSorting' => false, //tag for sorting - true or false
         .........
  ));
Backstairs answered 19/9, 2014 at 7:8 Comment(0)
U
0

If you use GridView

Then you can do that:

$dataProvider =  new yii\data\ActiveDataProvider([
        'sort'=>false,
    'query' => **some query here**
]);

or if you want to sort certain columns:

$dataProvider =  new yii\data\ActiveDataProvider([
            'sort'=>['attribute'=>[**attribute names here**]],
        'query' => **some query here**
    ]);

and then use this data provider in your GridView widget:

<?= GridView::widget([
     'dataProvider'=>$dataProvider,
      ...
]) ?>
Uchish answered 1/2, 2018 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.