JQGRID turn on/off column sorting
Asked Answered
B

2

6

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.

Brandenburg answered 2/5, 2012 at 16:41 Comment(2)
Providing example code would be helpful to get an answer.Colvin
Would this work for you? Update the colModel for the grid, changing/adding/removing the sortable and index attributes for the column in question, then reload the grid.Waterscape
P
16

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 :)

Pluvial answered 4/5, 2012 at 8:1 Comment(0)
R
1
$("#jqGrid").jqGrid({
    colModel: [ { label: 'Category Name', name: 'CategoryName', width: 75, **sortable: false** }]
});
Redemptioner answered 11/7, 2016 at 8:2 Comment(1)
Why should the OP "try this"? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO that may find this question and be reading your answer.Embolic

© 2022 - 2024 — McMap. All rights reserved.