如何默认显示来自JQgrid的子网格?

时间:2014-01-28 14:01:47

标签: jqgrid default subgrid

TypeError:this.each不是函数

返回this.each(function(){这是我的代码来自子网格序列:

subGrid : true, 

        subGridRowExpanded: function(subgrid_id, row_id) {
          //var projectIdRow = $('#list2').jqGrid('getCell',rowId,'projectid');
          var subgrid_table_id;
          subgrid_table_id = subgrid_id+"_t";
          $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"'></table>");
          $("#"+subgrid_table_id).jqGrid({
            url:"/taskuri/subGrid/?id="+row_id,
            datatype: "json",
            colNames: ['SubTask',' ','Pri','Responsabil','Alocator','Alocat','Deadline','Estimat','Lucrat',' '],
            colModel: [ 
              {name:"SubTask",index:"SubTask",width:'687%',align:"left",sortable:false},
              {name:'finished',index:'finished', width:'40%',sortable:false},
              {name:"Pri",index:"Pri",width:'56%', sortable:true},
              {name:"Responsabil",index:"Responsabil",width:'128%',sortable:false},
              {name:"Alocator",index:"Alocator",width:'130%',sortable:false},
              {name:"Alocat",index:"Alocat",width:'110%',sortable:false},
              {name:"Deadline",index:"Deadline",width:'110%',sortable:false},
              {name:"Estimat",index:"Estimat",width:'76%',align:"right",sortable:false},
              {name:"Lucrat",index:"Lucrat",width:'90%',align:"right"},
              {name:"Delete",index:"Delete",width:'90%',align:"right"},
            ],
            height: '100%',
            rowNum:20,
           });
        }, 

我想要的东西。首先默认显示子网格(当我访问页面时)。其次,如果没有数据,则没有点显示子网格。我怎样才能做到这一点?下面我上传一张图片,看看它是如何显示的,如果没有数据的话。谢谢 enter image description here

我试过这个方法:

gridComplete: function(){ 
               var grid = $("#list2");
               var svi_id = grid.jqGrid('getDataIDs');
               $.each(svi_id, function (index, rowId) {
                    $(this).jqGrid.expandSubGridRow(rowId); 
// or grid.jqGrid.expandSubGridRow(rowId); 

               });
        },

,结果是错误:TypeError:this.each不是函数 return this.each(function(){{(firebug)。有什么问题?

2 个答案:

答案 0 :(得分:0)

检查expandSubGridRow ....您可以在父网格的loadcomplete中执行此操作!!

    loadComplete: function () {
        var timeOut = 50;
        var rowIds = $("#list").getDataIDs();
        $.each(rowIds, function (index, rowId) {
            setTimeout(function () {
                $("#list").expandSubGridRow(rowId);
            }, timeOut);
            timeOut = timeOut + 200;
        });
    }

答案 1 :(得分:0)

这是默认显示子网格

的正确代码
 gridComplete: function(){ 
                   var grid = $("#list2");
                   var svi_id = grid.jqGrid('getDataIDs');
                   $.each(svi_id, function (index, rowId) {
                        grid.jqGrid('expandSubGridRow',rowId);
                   });
            },