jqgrid嵌套子网格4级子网格始终返回子网格的第一个rowid [英] jqgrid nested subgrid 4th level subgrid always returns first rowid of the subgrid

查看:105
本文介绍了jqgrid嵌套子网格4级子网格始终返回子网格的第一个rowid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jqGrid v4.3.2
ie9
win7企业

jqGrid v4.3.2
ie9
win7enterprise

我正在使用以下代码生成子网格:

I'm using the following code to generate subgrids:

http://www.trirand.com/blog/jqgrid/jqgrid.html ->高级->网格作为子网格

http://www.trirand.com/blog/jqgrid/jqgrid.html - > Advanced -> Grid as SubGrid

我做到了,我有

第一级子网格确定
  第二级子网格确定
   第三级子网格 OK
    第四级子网格它为第三级Lvl sg的每一行加载子网格OK,但它仅显示第三级Lvl sg

1st level subgrid OK
  2nd level subgrid OK
    3rd level subgrid OK
      4th level subgrid It loads the subgrid OK for every row of the 3rd Lvl sg, but it shows data only of the first row id of the 3rd Lvl sg

当我检查开发人员工具时,我看到请求总是发送第三个子网格的第一行的ID,我知道如何将自定义参数附加到已经尝试过的postData以及Oleg K jqgrid中subgrid的postData无法正常工作吗?(此方法在我的情况是,数据未添加到请求中)

When I check the developer tools I see that the request always sends the id of the first row of the third subgrid, I know how to append custom parameters with postData which I have already tried and also this answer from Oleg K postData for subgrid in jqgrid not working? (this one doesn't work in my case, data is not added to the request)

我试图从以下事件中返回rowdid,但是没有运气,它仍然返回第三个子网格的第一行ID,因此,对于第三个子网格的每一行,子子网格总是返回相同的结果.

I've tried to return the rowdid from the following events but no luck, it stills returns the first row id of the third subgrid and thus, for every row on the third subgrid the children subgrid always returns the same.

subGridRowExpanded  //always returns first row id of the third grid
onSelectRow  //doesn't fire if we click the + icon for expanding the subgrid
beforeSelectRow  //doesn't fire at all

另一个奇怪的行为是,如果我单击第三级子网格上的任何行,它只会选择第一行.

Another strange behaviour is that if i click any row on the third level subgrid it only selects the first row.

不,抱歉,不能使用treegrid.

No, using treegrid is not an option, sorry.

我正在考虑将单击事件绑定到第三级子网格的每行的加号图标(第一个单元格)上,并触发expandSubGridRow,但是问题仍然存在,如何获取我单击的行的rowid <第三级子网格中的em> ?

I'm thinking of binding a click event on the plus icon (first cell) of each row of the 3rd level subgrid and fire a expandSubGridRow, but the question remains, how do I get the rowid of the row I clicked of the third level subgrid?

最诚挚的问候,在此先感谢您的帮助.

Best regards and thanks in advance, any help is much appreciated.

jQuery("#listsg11").jqGrid({
    url:'server.php?q=1',
    datatype: "xml",
    height: 190,
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:55},
        {name:'invdate',index:'invdate', width:90},
        {name:'name',index:'name', width:100},
        {name:'amount',index:'amount', width:80, align:"right"},
        {name:'tax',index:'tax', width:80, align:"right"},      
        {name:'total',index:'total', width:80,align:"right"},       
        {name:'note',index:'note', width:150, sortable:false}       
    ],
    rowNum:8,
    rowList:[8,10,20,30],
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    multiselect: false,
    subGrid: true,
    caption: "Grid as Subgrid",
    subGridRowExpanded: function(subgrid_id, row_id) {
        var subgrid_table_id;
        subgrid_table_id = subgrid_id+"_t";
        $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
        jQuery("#"+subgrid_table_id).jqGrid({
            url:"subgrid.php?q=2&id="+row_id,
            datatype: "xml",
            colNames: ['No','Item','Qty','Unit','Line Total'],
            colModel: [
                {name:"num",index:"num",width:80,key:true},
                {name:"item",index:"item",width:130},
                {name:"qty",index:"qty",width:70,align:"right"},
                {name:"unit",index:"unit",width:70,align:"right"},
                {name:"total",index:"total",width:70,align:"right",sortable:false}
            ],
            subGrid: true,
            caption: "Grid as Subgrid",
            subGridRowExpanded: function(subgrid_id2, row_id2) {
                var subgrid_table_id2;
                subgrid_table_id2 = subgrid_id2+"_t";
                $("#"+subgrid_id2).html("<table id='"+subgrid_table_id2+"' class='scroll'></table>");
                jQuery("#"+subgrid_table_id2).jqGrid({
                    url:"subgrid.php?q=3&id="+row_id2,
                    datatype: "xml",
                    colNames: ['No','Item','Qty','Unit','Line Total'],
                    colModel: [
                        {name:"num",index:"num",width:80,key:true},
                        {name:"item",index:"item",width:130},
                        {name:"qty",index:"qty",width:70,align:"right"},
                        {name:"unit",index:"unit",width:70,align:"right"},
                        {name:"total",index:"total",width:70,align:"right",sortable:false}
                ],
                subGrid: true,
                caption: "Grid as Subgrid",
                subGridRowExpanded: function(subgrid_id3, row_id3) {
                    var subgrid_table_id3;
                    subgrid_table_id3 = subgrid_id3+"_t";
                    $("#"+subgrid_id3).html("<table id='"+subgrid_table_id3+"' class='scroll'></table></div>");
                    jQuery("#"+subgrid_table_id3).jqGrid({
                        url:"subgrid.php?q=4&id="+row_id3,
                        datatype: "xml",
                        colNames: ['No','Item','Qty','Unit','Line Total'],
                        colModel: [
                            {name:"num",index:"num",width:80,key:true},
                            {name:"item",index:"item",width:130},
                            {name:"qty",index:"qty",width:70,align:"right"},
                            {name:"unit",index:"unit",width:70,align:"right"},
                            {name:"total",index:"total",width:70,align:"right",sortable:false}
                    ]
                    });
                }
                });
            }
        });
    }
});

推荐答案

我仍然假设页面上显示的* all **子网格中的* data之间存在一些id冲突.例如,如果您在某些级别从已打开的网格中插入某些数据,则以"1"作为行ID的数据不应在任何子网格中插入其他数据.

I still suppose that you have some id conflicts between *data in *all** subgrids displayed on the page. For example if you inserts on some level in some from opened grids the data having "1" as the rowid no other data in any subgrid should be inserted with the same subgrid.

为便于理解:在所有子网格级别的"num"列中都使用key:true.相应的值将不仅在网格单元内部(在<td>here</td>内)的"num"列中使用.它也将用作网格或子网格(<tr>)行的id属性的值. HTML不允许在页面上重复ID.因此,您确实插入了具有ID重复项的元素,因此可能会产生一些奇怪的效果,在不同的Web浏览器中可能会有所不同.例如,您将尝试选择一个行,然后将其选择为另一行.选择行还可能遇到更多困难的问题.因此,您应该填充网格,以使 id在整个页面上都是唯一的.

For understanding: You use key:true for the "num" column on all level of subgrids. The corresponding value will be not just used in "num" column inside of grid cell (inside of <td>here</td>). It will be also used as the value of id attributes of the row of the grid or subgrid (<tr>). HTML don't permit id duplicates on the page. So it you do insert elements with id duplicates you can have some strange effects which could be different in different web browsers. For example you will try to select one row and it will be selected another one. You can also have much more hard problems as selection of rows. So you should fill the grids so than ids will be unique on the whole page.

要确保不存在ID重复的问题,可以使用idPrefix选项.您可以在0级使用

To be sure that the problem with id duplicates is not exists you can use idPrefix option. On the level 0 you can use

idPrefix: "m"

(来自main).对于下一级的子网格,您可以使用

(from main) for example. For the subgrid on the next level you can use

idPrefix: "s" + row_id + "_"

用于下一级子网格

idPrefix: "s" + row_id + "_" + row_id2 + "_"

idPrefix: "s" + row_id + "_" + row_id2 + "_" + row_id3 + "_"

jQuery("#"+subgrid_table_id3)的定义在所有先前级别的子网格的subGridRowExpanded中.因此,您可以访问外部范围内定义的row_idrow_id2.

The definition of jQuery("#"+subgrid_table_id3) is inside of subGridRowExpanded of subgrids of all previous levels. So you can access row_id and row_id2 defined on the outer scope.

我希望,在进行更改之后,您不会遇到任何奇怪的问题,如您所描述的问题.

I hope, that after the changes you will don't have any strange problems like the problems which you described.

这是DUPLICATES的示例

here is sample of DUPLICATES

这篇关于jqgrid嵌套子网格4级子网格始终返回子网格的第一个rowid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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