Yii provides sorting functionality for listing. How can I disable sorting so that my records will not get sorted when clicked on column header?
Disable sorting in header column of Yii CGridView
Asked Answered
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,
...
]) ?>
© 2022 - 2024 — McMap. All rights reserved.