2010-10-21 77 views
4

有没有办法让网格上的所有列都不可排序,而不是将sortable:false添加到每列中?我知道你可以在网格级设置全局选项,但不知道你是否可以在colModel级别完成。jqGrid - 使所有的列不可排序?

回答

4

jqGrid中没有全局设置,与colModel中的sortable:false对应。此外jqGrid直接读取colModel的值不使用每个列元素的一些默认设置。所以你必须明确地在每一列中定义sortable:false

在另一边,你可以做以下操作:

// 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 
}); 

在路上你也许可以存档您想同样的结果,但在其他的方式。

+0

感谢奥列格。我们为每列添加了“sortable:false”。 – 2010-10-22 20:40:44

+1

@Marcus:我建议并可以说服Tony在下一个版本的jqGrid模板中添加'colModel'中的列(请参阅http://www.trirand.com/blog/?page_id=393/feature-request/templates- for-columns-in-colmodel /更多细节)。 https://github.com/tonytomov/jqGrid/上的当前jqGrid源已包含新功能。我想,这个消息对你来说会很有趣。 – Oleg 2010-12-07 11:41:04

+0

非常感谢Oleg! – 2010-12-07 16:18:03

6

您可以使用colmodel模板来实现这个

cmTemplate: {sortable:false}