Rukmi Patel
Rukmi Patel

Reputation: 2561

Disable sorting in header column of Yii CGridView

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

Upvotes: 5

Views: 12399

Answers (3)

godot
godot

Reputation: 3545

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,
      ...
]) ?>

Upvotes: 0

Snopzer
Snopzer

Reputation: 1692

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

Upvotes: 0

SuVeRa
SuVeRa

Reputation: 2904

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

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

Upvotes: 23

Related Questions