jqGrid子网格数据未显示



我看到有人问我同样的问题,但没有一个包含我可以使用的答案。我使用的是jqgrid 4.4。主网格加载数据很好,在子网格中,我可以看到来自java控制器的响应,但不知道如何显示。

function(){ 
        jQuery("#subGrid").jqGrid({ 
            url: CONTEXT_ROOT+"/cartonPremium", 
            id:'gridtable', 
            datatype: "json", 
            height: 190, 
            jsonReader : {
                       root: 'gridModel', 
                       page: 'page',
                       total: 'total',
                       records: 'records',
                       repeatitems: false,      
                       id: '0'                     
             },              
            colNames:['idPremium','Name','Week', 'Departure Region' ],
            colModel:[ 
            {name:'idPremium',hidden:false, width:100},
            {name:'name',index:'name', width:300}, 
            {name:'sequence',index:'sequence', width:90}, 
            {name:'departureRegion',index:'departureRegion',width:100} 
            ], 
            hidegrid: false,
            rowNum:20, 
            rowList:[20,40,80], 
            pager: '#psubGrid', 
            sortname: 'name', 
            viewrecords: true, 
            sortorder: "desc", 
            multiselect: false, 
            sortable: true,
            autowidth: false,
            pagerButtons:true,
            navigator:true,
            //loadonce: true,
            altRows: true,
            viewsortcols: [true,'vertical',true],
            subGrid: true,
            // define the icons in subgrid 
            subGridOptions: { 
                "plusicon" : "ui-icon-triangle-1-e", 
                "minusicon" : "ui-icon-triangle-1-s", 
                "openicon" : "ui-icon-arrowreturn-1-e"//, 
                //expand all rows on load 
                //"expandOnLoad" : true 
            }, 
            subGridRowExpanded: function(subgrid_id, row_id) { 
                var subgrid_table_id, pager_id; 
                subgrid_table_id = subgrid_id+"_t"; 
                pager_id = "p_"+subgrid_table_id; 
                $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
                jQuery("#"+subgrid_table_id).jqGrid({ 
                    url:CONTEXT_ROOT+"/premiumCasePackOption?rowId="+row_id, 
                    datatype: "json", 
                    colNames:['idCasePackOptions','cypharecommended','distributorapproved', 'height', 'length','statuscode','weight','width'],
                    colNames:['idCasePackOptions'],
                    colModel: [ 
                        {name:'idCasePackOptions', width:170,hidden:false}      
                    ], 
                    rowNum:8, 
                    pager: pager_id, 
                    sortname: 'idCasePackOptions', 
                    sortorder: "asc", 
                    sortable: true,
                    height: 400 
                }); 
            jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:true,del:false}); 
            }   
        }
    );
    jQuery("#subGrid").jqGrid('navGrid','#psubGrid',{add:false,edit:false,del:false});
}

);

以下是服务器的响应

{"total":1,"page":1,"gridModel":[{"idCasePackOptions":1},{"idCasePackOptions":2},{"idCasePackOptions":3},{"idCasePackOptions":4},{"idCasePackOptions":5},{"idCasePackOptions":6}],"records":6,"rows":8}

救命!!我错过了什么?

我终于开始工作了。。。yipeee!!!亚网格中缺少的魔力

jsonReader: {
  root: 'gridModel',
  repeatitems: false
}

所以工作版本看起来像这个

$(document).ready(
function(){ 
        jQuery("#subGrid").jqGrid({ 
            url: CONTEXT_ROOT+"/cartonPremium", 
            id:'gridtable', 
            datatype: "json", 
            height: '100%' ,
            mtype: 'POST',
            jsonReader : {
                       root: 'gridModel', 
                       page: 'page',
                       total: 'total',
                       records: 'records',
                       repeatitems: false,      
                       id: '0'                
             }, 
            colNames:['idPremium','Name','Week' ],
            colModel:[ 
            {name:'idPremium',hidden:false, width:100},
            {name:'name',index:'name', width:300}, 
            {name:'sequence',index:'sequence', width:90}
            ], 
            hidegrid: false,
            rowNum:20, 
            rowList:[20,40,80], 
            pager: '#psubGrid', 
            sortname: 'name', 
            viewrecords: true, 
            sortorder: "desc", 
            multiselect: false, 
            sortable: true,
            autowidth: false,
            pagerButtons:true,
            navigator:true,
            //loadonce: true,
            altRows: true,
            viewsortcols: [true,'vertical',true],
            subGrid: true,
            // define the icons in subgrid 
            subGridOptions: { 
                "plusicon" : "ui-icon-triangle-1-e", 
                "minusicon" : "ui-icon-triangle-1-s", 
                "openicon" : "ui-icon-arrowreturn-1-e",
                "reloadOnExpand" : true
            }, 
            subGridRowExpanded: function(subgrid_id, row_id) { 
                var subgrid_table_id, pager_id; 
                subgrid_table_id = subgrid_id+"_t"; 
                pager_id = "p_"+subgrid_table_id; 
                $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
                jQuery("#"+subgrid_table_id).jqGrid({ 
                    url:CONTEXT_ROOT+"/premiumCasePackOption?rowId="+row_id, 
                    datatype: "json", 
                    mtype: 'POST',
                    colNames:['idCasePackOptions','cypharecommended','distributorapproved', 'height', 'length','statuscode','weight','width'],
                    colModel: [ 
                        {name:'idCasePackOptions', width:170,hidden:false}, 
                        {name:'cypharecommended',index:'cypharecommended', width:170},
                        {name:'distributorapproved',index:'distributorapproved', width:170},
                        {name:'height',index:'height', width:100},
                        {name:'length',index:'length', width:80, align:"right"},
                        {name:'statuscode',index:'statuscode', width:90, align:"right"},        
                        {name:'weight',index:'weight', width:100,align:"right"},        
                        {name:'width',index:'width', width:100}     
                    ], 
                    rowNum:8, 
                    pager: pager_id, 
                    sortname: 'idCasePackOptions', 
                    sortorder: "asc",
                    viewrecords: true, 
                    sortable: true,
                    height: '100%' ,
                    autowidth: true,
                    jsonReader: {
                        root: 'gridModel',
                        repeatitems: false
                    }
                }); 
            jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:true,del:false}); 
            }
        }
    );
    //jQuery("#subGrid").jqGrid('navGrid','#psubGrid',{add:false,edit:false,del:false});
}

);

如果给定的函数之一不存在,则子网格中的数据也不会显示。因此,如果你打错了字,就会显示空行:

afterSave: ReloadSubGrid, onError: UpdateFailed, delOptions:...
...
function ReloadSbuGrid(rowid, response) {
    ...
}

类型:ReloadSbuGrid本应为ReloadSubGrid

相关内容

  • 没有找到相关文章

最新更新