jqGrid 自动加载树网格问题。 。

发布于 2024-11-05 03:41:21 字数 2119 浏览 4 评论 0原文

我在自动加载树网格时遇到问题。 目前我的结构只有 2 层深。

1
    a
    b
    c 
2
    a

当我单击展开节点时,网格似乎再次添加根节点的另一个实例,以及应根据所选根节点显示的任何子节点。

1
1
    a
    b
    c

这是选择根节点之前的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

这是选择根节点之后的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
    <row>
        <cell>5207</cell>
        <cell>Child 1</cell>
        <cell>1</cell>
        <cell>1112</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

另外,这是我的配置:

$(document).ready(function(){
    $("#gReport").jqGrid({
        treeGrid: true,
        treeGridModel: 'adjacency',
        ExpandColumn: 'company',
        url: document.forms['frmReport'].elements['gaddr'].value,
        datatype: 'xml',
        mtype: 'GET',
        colNames: ["ID", "Company"],
        colModel: [
            {name: 'id', index: 'id', width: 1, hidden: true, key: true},
            {name: 'company', index: 'company', width: 40, hidden: false, sortable: true}
        ],
        rowNum: -1,
        width: 980,
        height: 'auto',
        pager: false,
        caption: ''
    }),
});

任何帮助将不胜感激。 谢谢。 -克里斯

I am having a problem with an autoloading tree grid.
At present I have a structure that is only 2 levels deep.

1
    a
    b
    c 
2
    a

When I click to expand a node, the grid seems to add another instance of the root node again as well as whichever sub node(s) should have been shown based on the the root node selected.

1
1
    a
    b
    c

Here is a look at the XML before selecting the root node:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

And here is a look at the XML after selecting the root node:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
    <row>
        <cell>5207</cell>
        <cell>Child 1</cell>
        <cell>1</cell>
        <cell>1112</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

Also, here is my config:

$(document).ready(function(){
    $("#gReport").jqGrid({
        treeGrid: true,
        treeGridModel: 'adjacency',
        ExpandColumn: 'company',
        url: document.forms['frmReport'].elements['gaddr'].value,
        datatype: 'xml',
        mtype: 'GET',
        colNames: ["ID", "Company"],
        colModel: [
            {name: 'id', index: 'id', width: 1, hidden: true, key: true},
            {name: 'company', index: 'company', width: 40, hidden: false, sortable: true}
        ],
        rowNum: -1,
        width: 980,
        height: 'auto',
        pager: false,
        caption: ''
    }),
});

Any help would be greatly appreciated.
Thanks.
-chris

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

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

发布评论

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

评论(1

岁吢 2024-11-12 03:41:21

你所描述的行为真的很有趣!问题在于子节点“Child 1”未标记为叶后面的行 false ;1112 是 isLeaf 值)。因此,在用户单击“Child 1”后,必须显示其所有子项。由于您的输入中未定义“已加载”列的值,因此树网格尝试从服务器加载 id=5207 的“Child 1”节点的子节点。因此,对同一 url 的请求带有附加参数

nodeid=5207&parentid=1112&n_level=1

就完成了。因为您的服务器只是忽略参数并返回相同的 XML 数据,所以您会看到疯狂的图片

在此处输入图像描述

(请参阅演示此处)。
要解决此问题,您应该将“Child 1”节点标记为叶子:

<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>true</cell> <!-- here the "false" was changed to "true" -->
    <cell>false</cell>
</row>

并接收以下树网格

在此处输入图像描述

(请参阅此处的演示)或在具有“true”值的“已加载”列的 XML 文件:

<row>
    <cell>1112</cell>
    <cell>Parent 1</cell>
    <cell>0</cell>
    <cell>NULL</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>true</cell>  <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>
<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>false</cell> <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>

并接收网格

在此处输入图像描述

(请参阅演示此处)。我建议您以任何方式包含“已加载”列的“真实”值。您获得的额外优势是您可以在加载时扩展任何节点。例如,在最后一个演示中,我在根节点的“expanded”列中设置了“true”值,因此它将在加载时扩展。

The behavior which you described is really funny! The problem is that the child node "Child 1" is not marked as leaf (the line <cell>false</cell> after the <cell>1112</cell> is the isLeaf value). So after the user click on the "Child 1" all its children must be shown. Because the value for the column "loaded" is not defined in your input the tree grid try to load the children of the "Child 1" node having id=5207 from the server. So the request to the same url with additional parameters

nodeid=5207&parentid=1112&n_level=1

will be done. Because your server just ignore the parameters and get the same XML data back one see the crazy picture

enter image description here

(See the demo here).
To fix the problem you should either mark the "Child 1" node as the leaf:

<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>true</cell> <!-- here the "false" was changed to "true" -->
    <cell>false</cell>
</row>

and receive the following tree grid

enter image description here

(see the demo here) or add additional data in the XML file for the "loaded" column with the "true" value:

<row>
    <cell>1112</cell>
    <cell>Parent 1</cell>
    <cell>0</cell>
    <cell>NULL</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>true</cell>  <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>
<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>false</cell> <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>

and receive the grid

enter image description here

(see the demo here). I would recommend you to include "true" value for the "loaded" column in any way. The additional advantage which you receive is that you will be able to expand any node at the load time. In the last demo for example I set "true" value in the "expanded" column for the root node, so it will be expanded at the load time.

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