Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQGRID turn on/off column sorting

Is there anyway I can enable or disable column sorting during runtime?

I can remove or add the class that makes sorting possible, and when I remove it the column can't be sorted. But when I restore it the grid sorts that column automatically as if someone had sorted it.

like image 395
Alejandro Formanek Avatar asked May 02 '12 16:05

Alejandro Formanek


2 Answers

Yes, you can.

Let's write some context:

//Here you have your grid.
jQuery('#myGrid');
//Here the definition of a colModel
{name:'Name', index:'name', sortable:true, align:'left', required: true, editable:true, edittype:'text'}

And now, when you click on some button you call a function, which is supposed to disable sorting from the column Name. This is what the function should look like.

function disableSorting(){
    jQuery('#myGrid').setColProp('Name', {sortable: false});
}

Tested and it works :)

like image 106
Hector Ordonez Avatar answered Nov 01 '22 03:11

Hector Ordonez


$("#jqGrid").jqGrid({
    colModel: [ { label: 'Category Name', name: 'CategoryName', width: 75, **sortable: false** }]
});
like image 1
Parthesh Mehta Avatar answered Nov 01 '22 02:11

Parthesh Mehta