Question

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

Was it helpful?

Solution

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

$this->widget('zii.widgets.CListView', array(
        ......
        'enableSorting' => false,
        ......
    )
);

OTHER TIPS

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
         .........
  ));

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,
      ...
]) ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top