jqGrid:子网格不填充数据

发布于 2024-11-16 16:14:46 字数 3841 浏览 4 评论 0 原文

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

您可以在屏幕截图中 FireBug 输出的底部看到 XML 响应。我已通读该 XML,它看起来是有效的。凭直觉,我还将 XML 输出粘贴到 此页面 中,而且它似乎缩进得很好。最重要的是,我还让 ajax 调用返回一些非常基本的值,无论我到目前为止尝试了什么,网格仍然是空的。

在此处输入图像描述

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

------------------------------------------------------
|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 响应/subgrids 可以在此要点中找到

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.

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.

enter image description here

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.

The code for the subgrid is:

$("#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
  }
});

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

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

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

发布评论

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

评论(1

冧九 2024-11-23 16:14:46

我可以重现该问题并分析jqGrid的子网格模块的代码。我的解释是: expandOnLoad: true 属性您使用的“nofollow">subGridOptions仅在主网格上的“本地”数据类型的情况下才起作用。我在文档中没有找到对此的相应说明,但确实如此。

在4.1版本中使用了delayOnLoad选项,但它不能正确工作。在版本 4.1.1 中,修复之后,该选项不再使用,并且在添加后立即使用主网格中的一行。问题是,如果前一个ajax请求的响应直到最后都没有处理,jqGrid使用.grid.hDiv.loading属性来跳过ajax请求。主网格的 $.ajax 请求的 beforeSend 处理程序内部(请参阅 此处)将被调用 beginReq() 第一行位于

ts.grid.hDiv.loading = true;

成功 $ 的处理程序。 ajax 请求 addXmlData 方法将被调用,该方法调用 addSubGrid 主网格的每一行,调用 .trigger('click'); 上网格行的“展开”图标。结果 populatesubgrid 将是在.grid.hDiv.loading之前在所有网格行上调用将被更改为false href="https://github.com/tonytomov/jqGrid/blob/v4.1.1/js/grid.base.js#L1666" rel="nofollow">endReq成功结束时 处理程序。所以在 populatesubgrid 将测试 ts.grid.hDiv.loading 的方法,相应的 $.ajax 调用将被跳过并且行将不会扩展

因此,我可以重复我的分析的简短结果:不要使用 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.

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;

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.

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

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