Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid - make all columns not sortable?

Is there a way to make all columns on a grid NOT sortable other than adding sortable:false to each column? I know you can set global options at the grid level but didn't know if you could do it at the colModel level.

like image 452
Marcus Leon Avatar asked Oct 21 '10 16:10

Marcus Leon


People also ask

How to disable sorting in jqGrid?

To enable or disable the sorting of a Grid column, you can set its sortable property to false. In the code example below, the sorting of the "ShipName" column is disabled. });

How do I sort a column in jqGrid?

So you should do the following: $('#yourgrid'). jqGrid('setGridParam', {sortname: 'yourColumn', sortorder: 'asc'}). trigger('reloadGrid', [{page: 1}]); . Moreover you should close the quote in $('#mybutton) .


2 Answers

You can use colmodel template to achieve this

cmTemplate: {sortable:false}
like image 74
Shashi Avatar answered Oct 29 '22 09:10

Shashi


There are no global setting in jqGrid which corresponds to the sortable:false from the colModel. Moreover jqGrid read directly the value of colModel without usage some default setting per every column element. So you have to define sortable:false in every column explicitly.

On the other side you can do following:

// we define simplified column model without repeating of the same information
var cm = [
    {name:'id', key: true},
    {name:'name'},
    // ...
];
// new we define "our standard" properties which will be the same in all columns
var myStdModel = {width: 150, sortable: false};

// we extend (or overwrite) "our standard" properties
for (var i=0; i<cm.length; i++) {
    $.extend(cm, myStdModel);
    cm.index = cm.name;
}

$("#list").jqGrid ({
    colModel: cm, // we use the column model built before
    // all other settings
});

In the way you can probably archive the same results which you want, but in the other way.

like image 28
Oleg Avatar answered Oct 29 '22 08:10

Oleg