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

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

问题描述

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

1一种乙C2一种

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

11一种乙C

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

<page>1</page><total>1</total><记录>1</记录><行><单元格>1112</单元格><细胞>亲本1</细胞><单元格>0</单元格><单元格>NULL</单元格><单元格>假</单元格><单元格>假</单元格></row></rows>

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

<page>1</page><total>1</total><记录>1</记录><行><单元格>1112</单元格><细胞>亲本1</细胞><单元格>0</单元格><单元格>NULL</单元格><单元格>假</单元格><单元格>假</单元格></row><行><细胞>5207</细胞><单元格>孩子1</单元格><单元格>1</单元格><单元格>1112</单元格><单元格>假</单元格><单元格>假</单元格></row></rows>

另外,这是我的配置:

$(document).ready(function(){$("#gReport").jqGrid({树格:真,treeGridModel: '邻接',ExpandColumn: '公司',网址:document.forms['frmReport'].elements['gaddr'].value,数据类型:'xml',mtype: 'GET',colNames:[ID",公司"],颜色型号:[{名称:'id',索引:'id',宽度:1,隐藏:真,键:真},{名称:'公司',索引:'公司',宽度:40,隐藏:假,可排序:真}],行数:-1,宽度:980,高度:'自动',寻呼机:假,标题: ''}),});

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

解决方案

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

<块引用>

nodeid=5207&parentid=1112&n_level=1

将完成.因为您的服务器只是忽略参数并返回相同的 XML 数据 一看疯狂的图片

(请参阅)或在具有true"值的已加载"列的 XML 文件:

<单元格>1112</单元格><细胞>亲本1</细胞><单元格>0</单元格><单元格>NULL</单元格><单元格>假</单元格><!-- 是叶子--><单元格>真</单元格><!-- 应该扩展--><单元格>真</单元格><!-- 已加载--></row><行><细胞>5207</细胞><单元格>孩子1</单元格><单元格>1</单元格><单元格>1112</单元格><单元格>假</单元格><!-- 是叶子--><单元格>假</单元格><!-- 应该扩展--><单元格>真</单元格><!-- 已加载--></row>

并接收网格

(参见此处).我建议您以任何方式为加载"列包含真"值.您获得的额外优势是您将能够扩展任何节点在加载时.例如,在上一个演示中,我在根节点的扩展"列中设置了真"值,因此它将在加载时扩展.

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

解决方案

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

(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

(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

(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天全站免登陆