2010-10-21 75 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}