how to disable sorting on GridView with GridView attributes

Good Morning everyone,

I am using GridView for exporting excel and pdf in view form, but i not able to disable sorting on GridView.

anyone can help me to resolve this issue. :rolleyes:

my GridView is




<?= GridView::widget([

        'dataProvider' => $model,

	'layout' => '{items}',

	'id' => 'course-grid',

        'columns' => [

            [

		'class' => 'yii\grid\SerialColumn',

		'header' => 'SI No.',

	    ],

            [

		'attribute' => 'course_name',	

	    ],

	    [

		'attribute' => 'course_code',

	    ],

        ],

    ]); ?>

Check this one http://stackoverflow.com/questions/27463817/how-to-enable-and-disable-sort-in-yii2-gridview

Hopefully it helps.

This solution works in GridView but i having two view page one for "index.php" and second one for "ExportPdfExcel.php".

so, now i want to disable sorting in "ExportPdfExcel.php" view page but not in "index.php".

go to your action in your controller then try this:





return $this->render('viewfilename', [

   'dataProvider' => new ActiveDataProvider([

    'query' => YourQuery,

    'sort' => false,

    'pagination' => [

      'pageSize' => anyNumber,

   ],

]),

]);



Hopefully it helps.

can i use


setsort()

for disable sorting in GridView