jqGrid:子网格不填充数据 [英] jqGrid: subgrid doesn't populate with data

查看:68
本文介绍了jqGrid:子网格不填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子网格,当您单击"Cheese"旁边的"+"符号时,ajax查询将触发,并且我看到了该子网格的列名,但是实际数据并未填充到该子网格中.无论我尝试扩展哪个网格,都会发生此问题,但是奶酪"示例如下所示.

I've got a subgrid that, when you click the "+" sign next to "Cheese", the ajax query fires, and I see the subgrid column names, but the actual data isn't populated into the subgrid. The problem happens regardless of which grid I try to expand, but the "Cheese" example is the one shown below.

您可以在屏幕快照的FireBug输出的底部看到XML响应.我已经阅读了该XML,它看起来是有效的.出于预感,我还将XML输出粘贴到此页面中,并且似乎可以缩进.最重要的是,我还让ajax调用返回了一些非常基本的值,无论到目前为止我尝试过什么,网格仍然为空.

You can see the XML response in the bottom portion of the FireBug output in the screenshot. I've read through that XML, and it looks to be valid. On a hunch, I also pasted the XML output into this page, and it seems to indent just fine. On top of that, I also had the ajax call return some very basic values, and no matter what I've tried so far, the grid remains empty.

您应该在子网格中看到的是:

What you should see in the subgrid is:

------------------------------------------------------
|Translations                    | Language | Active |
------------------------------------------------------
| It's cheesy goodness           |   EN     |   No   |
| fromage                        |   FR     |   No   | 
|                                |   DE     |   N/A  |   <-- "N/A" means there's no translation of "cheese" in German, currently in the database

    ... etc., with all supported languages listed.

子网格的代码为:

$("#translationsList").jqGrid({
    caption : "Translations",
    datatype : "xml",
    url : translationsFeed,
    editurl : translationsEdit,
    mtype : "get",
    pager : "#translationsPager",
    rowNum : 20,
    autowidth : true,
    sortname : "phrase",
    sortorder : "asc",
    viewrecords : true,
    multiselect : false,
    hidegrid : false,
    height : 300,
    altRows : true,
    rownumbers : true,
    toolbar : [false],
    colNames : ["phrase_id", "translation_id", "language_cd", "Phrase", "Translation", "Created", "Modified", "Active"],
    colModel : [
            { name : "phrase_id",                                   index : "phrase_id",            sortable : true,    search : false, editable : true,    edittype : "text",      editrules: { edithidden :true },                                    hidden : true},
            { name : "translation_id",                          index : "translation_id", sortable : false, search : false, editable : true,    edittype : "text",      editrules: { edithidden :true },                                    hidden : true},
            { name : "language_cd",                                 index : "language_cd",      sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { edithidden: true, required : true }, hidden : true },
        { name : "Phrase",              width:200,  index : "phrase",               sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { required : true } },
        { name : "Translation",         width:200,  index : "translation",      sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { required : false } },
        { name : "Created",             width:100,  index : "modify_dt",            sortable : true,    search : true },
        { name : "Modified",            width:100,  index : "create_dt",            sortable : true,    search : true },
        { name : "Active",              width:20,       index : "active",               sortable : true,    search : true,  editable : true,    edittype : "select",    editoptions:{value:"0:No;1:Yes"} }
    ],
    onSelectRow: function(id) {
            jQuery('#translationsList').editRow(id, true);
    },
    subGrid: true,
    subGridUrl: 'ajax/translations_subgrid_feed.php',
    subgridtype: 'xml',
    subGridModel : [{
      name      : ['Translations', 'Language', 'Active'],
      width     : [583, 70, 80],
      align     : ['left','right','right'],
      params    : ['phrase_id']
    }],
  subGridOptions: {
    plusicon : "ui-icon-plus",
    minusicon : "ui-icon-minus",
    openicon: "ui-icon-carat-1-sw",
    expandOnLoad: true,
    selectOnExpand : false,
    reloadOnExpand : true
  }
});

主/子网格的XML响应可以在此要点

The XML response for the main/subgrids can be found in this Gist

推荐答案

我可以重现该问题并分析jqGrid的子网格模块的代码.我的解释是: subGridOptions 的新expandOnLoad: true属性 仅在主网格上为本地"数据类型的情况下有效.我没有在文档中找到与此相关的注释,但是确实如此.

I could reproduce the problem and analysed the code of subgrid module of jqGrid. My explanation is: the new expandOnLoad: true property of the subGridOptions which you use can work only in case of 'local' datatype on the main grid. I don't found the corresponding remark about this in the documentation, but it is so.

在4.1版中使用了delayOnLoad选项,但是它不能正常工作.在版本4.1.1中,在修复之后,将不使用该选项,并在添加后立即使用该选项在主网格中的一行.问题在于,如果直到最后才处理前一个ajax请求的响应,jqGrid使用.grid.hDiv.loading属性跳过ajax请求.在主网格的$.ajax请求的beforeSend处理程序内部(请参见

In the version 4.1 are used delayOnLoad option, but it didn't works correct. In the version 4.1.1, after the fix the option are not used and immediately after adding a row in the main grid. The problem is that jqGrid use .grid.hDiv.loading property to skip ajax request if the response of the previous ajax request are not processed till the end. Inside of beforeSend handler of the $.ajax request of the main grid (see here) will be called beginReq() which first line is

ts.grid.hDiv.loading = true;

然后在成功$.ajax的处理程序请求 addXmlData 方法将被调用,该方法调用 addSubGrid 用于主网格的每一行,其调用 populatesubgrid 将是在.grid.hDiv.loading之前将所有网格行上称为的内容更改为 populatesubgrid 将测试ts.grid.hDiv.loading的方法,相应的$.ajax调用将被跳过,并且行将不会展开.

then inside of success handler of the $.ajax request the addXmlData method will be called, which call addSubGrid for every row of the main grid, which call .trigger('click'); on the "expand" icon of the grid row. As the result the populatesubgrid will be called on all grid rows before the .grid.hDiv.loading will be chaned to false inside of endReq at the end of success handler. So in the corresponding part of the populatesubgrid method where the ts.grid.hDiv.loading will be tested the corresponding $.ajax call will be skipped and the rows will be not expanded.

因此,我可以重复分析的简短结果:请勿使用expandOnLoad: true选项.它不适用于远程数据.

So I can repeat the short result of my analyses: don't use expandOnLoad: true option. It is not work on remote data.

这篇关于jqGrid:子网格不填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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