【问题标题】:jqgrid subgrid is not loading data (no Ajax call sent to the server)jqgrid subgrid 没有加载数据(没有 Ajax 调用发送到服务器)
【发布时间】:2014-07-06 20:29:19
【问题描述】:

我有以下设置 jqgrid (v 4.6.0)。

$(function () {

var JQGridDefaults = {
    caption: '',
    rowList: [10, 50, 100],
    datatype: 'json',
    height: '100%',
    viewrecords: true,
    mtype: 'GET',
    colNames: ['Item Control No', 'Item Short Description', 'ID'],
    colModel: [
        {
            name: 'ItemCode', index: 'ItemCode', search: true, width: 230, cellattr: makeCellContentWrap, searchoptions: {
                sopt: ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc'],
            },
            searchrules: {required: true}
        },
        {
            name: 'ItemShortDesc', index: 'ItemShortDesc', search: true, width: 300, cellattr: makeCellContentWrap, searchoptions: {
                sopt: ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc'],
            },
            searchrules: {required: true }
        }
        //Hidden Fields - Start
        { name: 'ItemID', hidden: true, key: true }
        //HiddenFields End
    ],
    pager: '#GridPager',
    rowNum: 10,
    sortname: 'ItemCode',
    sortorder: 'asc',
    url: '/Items/List',
    jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            userdata: "userdata",
            subgrid: {
                root: "rows",
                repeatitems: false
            }
        },
    //Sub Grid - Start
    subGrid: true,
    subGridBeforeExpand: function (pID, rowID) {
        console.log("Before Expand");
        var gridData = $(this).jqGrid('getRowData',rowID);
        if (gridData.ItemCode == "") {
            return false;
        }
    },
    subGridUrl: '/Items/Details',
    subGridModel: {
        name: ['Revision', 'ItemCode'],
        width: [50, 100],
        align: ['center', 'center'],
        mapping: ['Revision', 'ItemCode']
    },
    afterInsertRow: function (rowid, aData, rowelem) {
        // Remove the subgrid plus button except for rows that have exceptions
        if (aData.ItemCode  == "") {
            $('#' + rowid).children("td.sgcollapsed").unbind();
            $('#' + rowid).children("td.sgcollapsed").html("");
        }
    }
    //Sub Grid - END
};
var JQGridSearchDefaults = {
    multipleSearch: true,
    recreateFilter: true,
    showQuery: true,
    closeAfterSearch: true,
    closeAfterReset: true,
    searchOnEnter: true,
    closeOnEscape:true,
    width: 600
};

$('#Grid').jqGrid(JQGridDefaults).navGrid('#GridPager', { view: false, del: false, add: false, edit: false, refresh: true },
{},
{},
{},
JQGridSearchDefaults);

$('#Grid').jqGrid('setGridWidth', $('#Grid').parents('.main-content').width() - 2);

$(window).resize(function () {
    clearTimeout(this.id);
    this.id = setTimeout(function () {
        $('#Grid').jqGrid('setGridWidth', $('#Grid').parents('.main-content').width() - 2);
    }, 300);
});
});

子网格图标显示正确,但是当我点击展开图标时出现一个空行(没有标题,也没有发送 ajax 调用)

有人知道为什么没有发生 ajax 调用吗?

注意:我也尝试使用 'subgridtype' 参数并定义来进行服务调用,而该服务调用也没有进行 Ajax 调用。

subgridtype: function (rowidparam) {
            $.ajax({
                url: '/Items/Details',
                cache: false,
                type: 'Get',
                dataType: "json",
                data: { id: rowidparam.ItemID }
            }).done(function (data) {
                $('#Grid')[0].subGridJson(data, rowidparam.id);
            });
        },

【问题讨论】:

  • 尝试在浏览器(或扩展程序)中使用 javascript 调试器,以查看您的 javascript 是否在某些时候抛出异常,可能会阻止网格运行。当它不回去进行提取时,这通常是我遇到的问题。
  • 嗨,安迪。我试过了。但是没有抛出异常。如果我得到某种错误(异常),那么我可以知道什么是错误的。

标签: jqgrid


【解决方案1】:

subgridtype 必须是字符串,你试试 json 子网格类型:'json'

【讨论】:

    猜你喜欢
    • 2011-03-16
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多