1

我有一个子网格,当您单击“奶酪”旁边的“+”号时,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 响应可以在这个 Gist中找到

4

1 回答 1

1

我可以重现该问题并分析了 jqGrid 的 subgrid 模块的代码。我的解释是:您使用的subGridOptionsexpandOnLoad: true的新属性只能在主网格上的“本地”数据类型的情况下工作。我在文档中没有找到关于此的相应评论,但确实如此。

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

ts.grid.hDiv.loading = true;

然后在请求的成功处理程序内部调用addXmlData方法,该方法为主网格的每一行调用 addSubGrid,调用.trigger ('click'); 在网格行的“展开”图标上。结果,populatesubgrid在所有网格行上被调用,然后在处理程序结束时将其更改为endReq内部。因此,在将要测试的populatesubgrid方法的相应部分中,将跳过相应的调用,并且不会扩展行$.ajax.grid.hDiv.loadingfalsesuccessts.grid.hDiv.loading$.ajax

所以我可以重复我分析的简短结果:不要使用expandOnLoad: true选项。它不适用于远程数据。

于 2011-06-24T12:05:44.327 回答