子网格数据未显示在jqGrid 4.4.5中

时间:2013-04-14 22:03:28

标签: asp.net-mvc-4 jqgrid

我正在使用jqGrid 4.4.5和jQuery 1.9.1,在服务器端,我使用的是ASP.NET MVC 4(虽然我不认为这是问题的一部分)。

我有一个简单的jqGrid工作正常,我正在尝试添加一个简单的子网格。我已经配置了子网格,将其连接回服务器端的单独控制器,一切似乎工作正常,直到我需要显示子网格数据。

初始网格加载调用我的控制器的主数据方法,获取json并显示行。单击+符号会展开一行,从而导致回调到控制器的辅助数据方法。辅助方法将子网格数据作为有效的json返回(我使用Google Chrome开发工具验证了它)。子网格会展开并显示正确的行数和正确的标题,但这些值不会出现在单元格中。

我已经通过在线文档和各种建议,但似乎没有任何工作。我在jsonReader配置中玩了很多,但它似乎没有帮助(如果我将repeatitems设置为true,它根本不起作用)。将gridview从true翻转为false似乎也无济于事。

感谢任何帮助。

这是对子网格控制器方法的实际调用:

/Schedule/SubGridData?nd_=1365975664423&id=1002200&InspectionScheduleId=1002200&ItemTypeId=1000003

这是Google Chrome声称通过电话返回的数据:

{"rows":[{"cell":["Tony\u0027s HomeBrew","Icky Beer"]},{"cell":["Tony\u0027s WorkBrew","Tasty Beer"]}]}

这是网格配置:

    <script type="text/javascript">
    jQuery(document).ready(function () {
    jQuery('#GridDataBasic').jqGrid({
    autoencode:true,
    autowidth:true,
    caption:'Inspection Schedule',
    datatype:'json',
    jsonReader:{ repeatitems:false, id: 'InspectionScheduleId', subgrid: { root: 'rows', repeatitems: false, cell: 'cell', id: 'id' } },
    emptyrecords:'No record Found',
    gridview:false,
    height:'100%',
    loadui:'block',
    pager:'#pager',
    rowList:[10,15,20,50],
    rowNum:10,
    rowattr: function(rowData) {var dueDate = new Date(parseInt(rowData.DueDate.substr(6)));var nowDate = new Date();var colorDate = new Date(dueDate - (rowData.RedOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'redOffsetColor'}; }colorDate = new Date(dueDate - (rowData.OrangeOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'orangeOffsetColor'}; }colorDate = new Date(dueDate - (rowData.YellowOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'yellowOffsetColor'}; }colorDate = new Date(dueDate - (rowData.GreenOffsetInMinutes * 60000));if (nowDate > colorDate) { return {'class': 'greenOffsetColor'}; }},
    viewsortcols:[true,'vertical',true],
    shrinkToFit:true,
    url:'/Schedule/IndexGridData',
    viewrecords:true,
    subGrid: true,
    subGridUrl : '/Schedule/SubGridData',
    subGridModel : [ { 
    name : [ 'Item Name','Item Description' ],
    width : [ 50,50 ],
    align : [ 'left','left' ],
    params : [ 'InspectionScheduleId','ItemTypeId' ]
     } ],
    colModel: [
    {
      name:'InspectionScheduleId',
      hidden:true,
      key:true,
      label:'InspectionScheduleId',
      sortable:false,
      index:'InspectionScheduleId'
    },{
      name:'ItemTypeId',
      hidden:true,
      label:'ItemTypeId',
      sortable:false,
      index:'ItemTypeId'
    },{
      name:'GreenOffsetInMinutes',
      hidden:true,
      label:'GreenOffsetInMinutes',
      sortable:false,
      index:'GreenOffsetInMinutes'
    },{
      name:'YellowOffsetInMinutes',
      hidden:true,
      label:'YellowOffsetInMinutes',
      sortable:false,
      index:'YellowOffsetInMinutes'
    },{
      name:'OrangeOffsetInMinutes',
      hidden:true,
      label:'OrangeOffsetInMinutes',
      sortable:false,
      index:'OrangeOffsetInMinutes'
    },{
      name:'RedOffsetInMinutes',
      hidden:true,
      label:'RedOffsetInMinutes',
      sortable:false,
      index:'RedOffsetInMinutes'
    },{
      name:'ItemTypeName',
      label:'Item Type',
      sortable:false,
      index:'ItemTypeName'
    },{
      align:'center',
      name:'DueDate',
      formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'m/d/Y H:i:s'},
      label:'Due Date',
      sortable:true,
      index:'DueDate'
    }
    ]
    });
    });
    </script>

2 个答案:

答案 0 :(得分:0)

subgrid

jsonReader属性应包含repeatitems: true而非falsesubgrid属性的默认值为alsready {root:"rows", repeatitems: true, cell:"cell"}。所以我认为删除subgrid的{​​{1}}属性可以解决您的问题。

答案 1 :(得分:0)

如果您的某个给定功能不存在,则不会显示子网格中的数据(也是如此)。因此,如果您输入错字,将显示空行:

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

错字:ReloadSbuGrid应该是ReloadSubGrid