jqGrid自动加载Treegrid问题. . [英] jqGrid Autoloading Treegrid issue . .

查看:132
本文介绍了jqGrid自动加载Treegrid问题. .的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自动加载树形网格时遇到问题. 目前,我的结构只有2个层次.

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

在选择根节点之前,先看一下XML:

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>

下面是选择根节点后的XML:

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>

另外,这是我的配置:

$(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

推荐答案

您描述的行为确实很有趣!问题在于子节点子节点1" 未标记为叶子(<cell>1112</cell>之后的行<cell>false</cell>是isLeaf值).因此,在用户单击子代1"之后,必须显示其所有子代.由于未在输入中定义已加载"列的值,因此树形网格尝试从服务器加载id = 5207的子代1"节点的子代.因此,对具有其他参数的相同网址的请求

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

nodeid=5207&parentid=1112&n_level=1

将完成.因为您的服务器只是忽略了这些参数,而是获取了相同的XML数据,所以看到了疯狂的画面

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

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

(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>

并收到以下树状网格

(请参见演示此处)或在其中添加其他数据值为"true"的已加载"列的XML文件:

(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>

并接收网格

(请参见演示此处).我建议您以任何方式为已加载"列添加真"值.您获得的另一个好处是,您可以在加载时扩展任何节点.例如,在上一个演示中,我在根节点的"expanded"列中设置了"true"值,因此它将在加载时进行扩展.

(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.

这篇关于jqGrid自动加载Treegrid问题. .的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆