简体   繁体   中英

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?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM