在jqgrid中动态加载Subgrid

时间:2018-08-09 11:25:25

标签: javascript jqgrid subgrid

我正在尝试向subgrid添加数据,下面是我的代码:

 function showChildGrid(parentRowID, parentRowKey) {
    alert("********** " + parentRowKey);
            var childGridID = parentRowID + "_table";
            var childGridPagerID = parentRowID + "_pager";

            // add a table and pager HTML elements to the parent grid row - we will render the child grid here
            $('#' + parentRowID).append('<table id=' + childGridID + '></table><div id=' + childGridPagerID + ' class=scroll></div>');

            $("#" + childGridID).jqGrid({
       page: 1,
                colModel: [
                     { label: 'HANDLE', name: 'HANDLE', key: true, width: 75 },
                    { label: 'DOCUMENT NAME', name: 'DOCUMENT_NAME', width: 150 },
                    { label: 'ACTUAL PRINT QTY', name: 'ACTUAL_PRINT_QTY', width: 150 },
                    { label: 'SITE', name: 'SITE', width: 150 },
                    { label: 'PRINTER NAME', name: 'PRINTER_NAME', width: 150 }
                ],
        loadonce: true,
                width: 500,
                height: '100%',
        datatype: 'local',
                pager: "#" + childGridPagerID
            });
    var gridArrayData = [];
       // show loading message
            $.ajax({
                    url: "https://localhost:9434/DataFetch?QueryTemplate=CUSTOM/QUERY/GetPrintDetails&Param.1="+parentRowKey +"&Content-Type=text/json",
                    success: function (result) {
            console.log(" ================================== " + result + "  ************************** " + result.Rowsets.Rowset[0].Row.length);
            var rows = result.Rowsets.Rowset[0].Row;
            for (var i = 0; i < rows.length; i++) {
                var asyncPrintData = result.Rowsets.Rowset[0].Row[i];
                console.log("++++++++++++++++" + asyncPrintData + " ================== " + asyncPrintData.HANDLE);  
                gridArrayData.push({
                                        HANDLE: asyncPrintData.HANDLE,
                DOCUMENT_NAME: asyncPrintData.DOCUMENT_NAME,
                                        ACTUAL_PRINT_QTY: asyncPrintData.ACTUAL_PRINT_QTY,
                                        SITE: asyncPrintData.SITE,
                PRINTER_NAME: asyncPrintData.PRINTER_NAME
                                });
            console.log("++++++++++++++++" + gridArrayData);    
            // set the new data
            $("#" + childGridID).jqGrid('setGridParam', { data: gridArrayData});
            // refresh the grid
            $("#" + childGridID).trigger('reloadGrid'); 
        }
             }
                });

        }

我从Web服务获取数据,然后解析内容并将其放入数组中。

但是由于某种原因,这两个代码无法正常工作,并且我无法将数据加载到子网格中。

// set the new data
                $("#" + childGridID).jqGrid('setGridParam', { data: gridArrayData});
                // refresh the grid
                $("#" + childGridID).trigger('reloadGrid');

此外,我以与尝试填充子网格相同的方式填充父表。

父表在相同的逻辑下工作正常,但子网格却无法正常工作。

请让我知道我在做什么错

0 个答案:

没有答案