jqGrid (v4.1.2) 树网格的排序不适用于邻接模型

发布于 2024-12-03 05:19:59 字数 775 浏览 0 评论 0原文

我一直在使用 jqGrid,有一些 有用的问题关于邻接模型的答案,我得到了除了排序之外,我需要的所有东西都已连接并工作。

该问题实际上已在上面的答案链接中复制。谁能看到什么需要修复吗?奥列格似乎是这方面的专家!

我已经尝试过这个问题中的选项,但我认为当前版本(4.1.2 )可能有新的错误?请证明我错了。

我还在 http://trirand.com/blog/jqgrid/jqgrid.html< 上看到了示例/a> > > 3.4新功能>树网格邻接模型有效,但该示例未使用 此问题的第一个参考答案

I have been working with jqGrid and there are some useful questions and answers regarding the Adjacency model and I have got everything I need hooked up and working except sorting.

The problem is actually replicated in the answer link above. Can anyone see what needs fixing? Oleg appears to be the expert on this!

I have tried the options in this question but I think the current version (4.1.2) may have a new bug? Please prove me wrong.

I also see the example on http://trirand.com/blog/jqgrid/jqgrid.html > New in 3.4 > Tree grid Adjacency Model works but that example is not using the loaded:true property as described in the first referenced answer of this question

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2024-12-10 05:19:59

你是对的。这是我之前回答的数据中的一个小错误

经过一些调试后,我发现错误非常简单:应该使用 parent: "null"parent: null 代替 parent: ""

此外,您必须在网格中定义 sorttype 参数,才能对文本以外的任何数据进行正确排序。

您如何看到修改后的演示现在支持正确的本地排序:

< img src="https://i.sstatic.net/v0wLH.png" alt="在此处输入图像描述">

首先将按所选列对根元素进行排序,然后递归其所有子元素。

为了方便在搜索引擎中找到新代码,我添加了以下演示的代码:

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

You are right. It was small bug in the data from my previous answers about

After some debugging I find out that the error is very simple: one should use parent: "null" or parent: null in the data instead of parent: "".

Additionally you have to define sorttype parameters in the grid to have sorting correctly with any data other as texts.

How you can see the modified demo support now the local sorting correctly:

enter image description here

First will be sorted root elements by the chosen column and then recursively all its children.

To make easy to find the new code in the searching engine I include the code of the demo below:

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; }
    }
});
烟花易冷人易散 2024-12-10 05:19:59

通过排序,您的意思是自动对树选项进行排序,使它们落在适当的节点下,或者能够按其他行排序(第二个并没有真正意义,因为树组织数据,所以我不确定排序如何有意义。)

这是一个带有本地邻接树的 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}
];

By sorting, do you mean, auto-sorting the tree options such that they fall under the appropriate nodes, or being able to sort by other rows (the second of which doesn't really make sense, as the tree organizes the data, so I'm not sure how sorting would make sense.)

Here is a jsFiddle with a local adjacency tree - is this a better description of your problem? For example, in the data below, the id = 4 or 5 should belong to id = 1, but instead they show up under 3.

Here, the data is:

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}
];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文