子网格未填充



我试图在不使用subgridurl的情况下用json数据填充子网格(因为这将调用每行扩展的页面)。但我得到错误:"t.rows is undefined"(在grid.base.js)。代码如下:使用的模块版本:

  1. jquery-1.6.2.js
  2. jqGrid 3.3.2

提前感谢。

        jQuery(gridID).jqGrid({
            url: dataURL,
            datatype: "json",
            colNames: ['ID', 'FirstName', 'LastName', 'Address1', 'Address2', 'City', 'Country'],
            colModel: [
                    { name: 'id', width: 200, sortable: false },
                    { name: 'firstName', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} },
                    { name: 'lastName', width: 200, sortable: false, hidden: true },
                    { name: 'address1', width: 200, sortable: false, hidden: true },
                    { name: 'address1', width: 200, sortable: false, hidden: true },
                    { name: 'city', width: 200, sortable: false, hidden: false},
                    { name: 'country', width: 200, sortable: false, hidden: false}
                ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager2',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption: "TEST",
            height: "400px",
            subGrid: true,
            subGridRowExpanded: function(subgrid_id, row_id) {
                subGridID = subgrid_id;
                jQuery("#" + subGridID).html("<div style='margin-left:415px'><table id='" + subGridID + "' class='scroll'><tr><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td><td>Testing</td></tr></table></div>"); ;
                jQuery("#" + subGridID).jqGrid(
       {
           datatype: function(pdata) { getDataSubGrid(pdata); },
           colNames: ['ID', 'FirstName', 'LastName', 'Address1', 'Address2', 'City', 'Country'],,
            colModel: [
                    { name: 'id', width: 200, sortable: false },
                    { name: 'firstName', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} },
                    { name: 'lastName', width: 200, sortable: false, hidden: true },
                    { name: 'address1', width: 200, sortable: false, hidden: true },
                    { name: 'address1', width: 200, sortable: false, hidden: true },
                    { name: 'city', width: 200, sortable: false, hidden: false},
                    { name: 'country', width: 200, sortable: false, hidden: false}
                ],
           height: 100,
           rowNum: 20,
           sortorder: "asc",
           height: '100%'
       });
            }
        });
        jQuery("#mygrid").jqGrid('#mygrid', '#pager2', { edit: false, add: false, del: false });
    }

    function getDataSubGrid(pData) {
        gridId = "#mygrid_t";
        $.ajax({
            type: 'GET',
            contentType: "application/json; charset=utf-8",
            url: myURL,//myurl would get json data from web service
            data: '{}',
            dataType: "json",
            success: function(data, textStatus) {

                ReceivedClientDataForSubGrid(getMain(data).rows);
            },
            error: function(data, textStatus) {
                alert('An error has occured retrieving data subgrid!');
            }
        });
    }

    function ReceivedClientDataForSubGrid(data) {
        var thegrid = $("#" + subGridID);
        if ($(thegrid).length == 0) alert('NOT EXISTS');
        thegrid.clearGridData();
        alert(data.length);//this shows 10 
        for (var i = 0; i < data.length; i++) {
        thegrid.addRowData(i + 1, data[i]);
        }
    }

    function getMain(dObj) {
        if (dObj.hasOwnProperty('d'))
            return dObj.d;
        else
            return dObj;
    }

错误" .rows is undefined"通常意味着您使用了错误的HTML片段的网格。例如,如果您使用<div>而不是<table>,则会出现错误。

此外,我强烈建议您升级到当前的jqGrid版本4.1.2。今天使用jqGrid 3.3.2,特别是与相对较新的jQuery 1.6.2版本一起使用,可能会出现问题。这就像试图在新汽车上使用30年的旧汽油一样。

相关内容

  • 没有找到相关文章

最新更新