jqGrid - make all columns not sortable?
Asked Answered
T

2

6

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.

Toughen answered 21/10, 2010 at 16:31 Comment(0)
C
5

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.

Chappie answered 21/10, 2010 at 17:49 Comment(2)
Thanks Oleg. We went with adding sortable:false to each column.Toughen
@Marcus: I suggested and could convinced Tony to include in the next release of jqGrid templates for columns in colModel (see trirand.com/blog/?page_id=393/feature-request/… for more details). The current jqGrid sources on github.com/tonytomov/jqGrid already include the new feature. I think, that the news will be interesting for you.Chappie
M
7

You can use colmodel template to achieve this

cmTemplate: {sortable:false}
Misconstruction answered 15/3, 2012 at 8:38 Comment(0)
C
5

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.

Chappie answered 21/10, 2010 at 17:49 Comment(2)
Thanks Oleg. We went with adding sortable:false to each column.Toughen
@Marcus: I suggested and could convinced Tony to include in the next release of jqGrid templates for columns in colModel (see trirand.com/blog/?page_id=393/feature-request/… for more details). The current jqGrid sources on github.com/tonytomov/jqGrid already include the new feature. I think, that the news will be interesting for you.Chappie

© 2022 - 2024 — McMap. All rights reserved.