jqGrid(v4.1.2)treegrid不能使用Ajacency Model进行sorting
我一直在使用jqGrid,关于Adjacency模型有一些有用的问题和答案 ,除了sorting外,我已经拥有了所有我需要的东西。
问题实际上是在上面的答案链接中复制的。 任何人都可以看到需要修复? 奥列格似乎是这方面的专家!
我试过这个问题的选项,但我认为当前版本(4.1.2)可能有一个新的错误? 请certificate我错了。
我也看到http://trirand.com/blog/jqgrid/jqgrid.html上的例子> 3.4中的新增function>树网格邻接模型的作品,但该示例没有使用loaded:true
属性,如第一个引用的答案这个问题
你是对的。 这是我之前回答的数据中的一个小错误
经过一些debugging后,我发现这个错误非常简单:在数据中应该使用parent: "null"
或parent: null
,而不是parent: ""
。
此外,您必须在网格中定义sorttype
参数,以正确sorting其他任何数据作为文本。
你如何看到修改的演示支持现在正确的本地sorting:
首先将按选定的列对所有根元素进行sorting,然后对其所有子元素进行recursion。
为了方便在search引擎中查找新代码,我们在下面包含了演示代码:
var mydata = [ {id: "1", name: "Cash", num: "100", debit: "400.00", credit: "250.00", balance: "150.00", enbl: "1", level: "0", parent: "null", isLeaf: false, expanded: false, loaded: true}, {id: "2", name: "Cash 1", num: "1", debit: "300.00", credit: "200.00", balance: "100.00", enbl: "0", level: "1", parent: "1", isLeaf: false, expanded: false, loaded: true}, {id: "3", name: "Sub Cash 1", num: "1", debit: "300.00", credit: "200.00", balance: "100.00", enbl: "1", level: "2", parent: "2", isLeaf: true, expanded: false, loaded: true}, {id: "4", name: "Cash 2", num: "2", debit: "100.00", credit: "50.00", balance: "50.00", enbl: "0", level: "1", parent: "1", isLeaf: true, expanded: false, loaded: true}, {id: "5", name: "Bank\'s", num: "200", debit: "1500.00", credit: "1000.00", balance: "500.00", enbl: "1", level: "0", parent: "null", isLeaf: false, expanded: true, loaded: true}, {id: "6", name: "Bank 1", num: "1", debit: "500.00", credit: "0.00", balance: "500.00", enbl: "0", level: "1", parent: "5", isLeaf: true, expanded: false, loaded: true}, {id: "7", name: "Bank 2", num: "2", debit: "1000.00", credit: "1000.00", balance: "0.00", enbl: "1", level: "1", parent: "5", isLeaf: true, expanded: false, loaded: true}, {id: "8", name: "Fixed asset", num: "300", debit: "0.00", credit: "1000.00", balance: "-1000.00", enbl: "0", level: "0", parent: "null", isLeaf: true, expanded: false, loaded: true} ], grid = $("#treegrid"); $.jgrid.formatter.integer.thousandsSeparator=','; $.jgrid.formatter.number.thousandsSeparator=','; $.jgrid.formatter.currency.thousandsSeparator=','; grid.jqGrid({ datatype: "jsonstring", datastr: mydata, colNames: [/*"Id", */"Account", "Acc Num", "Debit", "Credit", "Balance", "Enabled"], colModel: [ //{name: 'id', index: 'id', width: 1, hidden: true, key: true}, {name: 'name', index: 'name', width: 180}, {name: 'num', index: 'acc_num', width: 80, formatter: 'integer', sorttype: 'int', align: 'center'}, {name: 'debit', index: 'debit', width: 80, formatter: 'number', sorttype: 'number', align: 'right'}, {name: 'credit', index: 'credit', width: 80, formatter: 'number', sorttype: 'number', align: 'right'}, {name: 'balance', index: 'balance', width: 80, formatter: 'number', sorttype: 'number', align: 'right'}, {name: 'enbl', index: 'enbl', width: 60, align: 'center', formatter: 'checkbox', editoptions: {value: '1:0'}, formatoptions: {disabled: false}} ], height: 'auto', gridview: true, rowNum: 10000, sortname: 'id', treeGrid: true, treeGridModel: 'adjacency', treedatatype: "local", ExpandColumn: 'name', caption: "Demonstrate how to use Tree Grid for the Adjacency Set Model", jsonReader: { repeatitems: false, root: function (obj) { return obj; }, page: function () { return 1; }, total: function () { return 1; }, records: function (obj) { return obj.length; } } });
通过sorting,你的意思是自动sorting树选项,使它们落在适当的节点下,或者能够sorting其他行(其中第二个没有意义,因为树组织数据,所以我不知道如何sorting是有道理的。)
这是一个jsFiddle与本地邻接树 – 这是一个更好的描述你的问题? 例如,在下面的数据中,id = 4或5应该属于id = 1,但是它们显示在3以下。
这里的数据是:
var mydata = [ {id: "1", label:"No 1", number:"02200220", status:"OPEN", level:"0", parent: "", isLeaf: false, expanded:true, loaded:true}, {id: "2", label:"No 2", number:"77733337", status:"ENTERED", level:"0", parent: "", isLeaf: false, expanded:true, loaded:true}, {id: "6", label:"No 2a", number:"12345123", status:"WIRED", level:"1", parent: "2", isLeaf: true, expanded:false, loaded:true}, {id: "3", label:"No 3", number:"02200111", status:"OPEN", level:"0", parent: "", isLeaf: false}, {id: "4", label:"No 1a", number:"02200221", status:"OPEN", level:"1", parent: "1", isLeaf: true, expanded:false, loaded:true}, {id: "5", label:"No 1b", number:"02242320", status:"CLOSED", level:"1", parent: "1", isLeaf: true, expanded:false, loaded:true} ];