Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 jqGrid 4.4.5中未显示子网格数据_Asp.net Mvc 4_Jqgrid - Fatal编程技术网

Asp.net mvc 4 jqGrid 4.4.5中未显示子网格数据

Asp.net mvc 4 jqGrid 4.4.5中未显示子网格数据,asp.net-mvc-4,jqgrid,Asp.net Mvc 4,Jqgrid,我使用jqGrid 4.4.5和jQuery 1.9.1,在服务器端,我使用ASP.NET MVC 4(尽管我不认为这是问题的一部分) 我有一个简单的jqGrid,它工作得很好,我正在尝试向它添加一个简单的子网格。我已经配置了子网格,将它连接回服务器端的一个单独的控制器,并且一切似乎都正常工作,直到我需要显示子网格数据为止 初始网格加载调用我的控制器的主数据方法,获取json并显示行。单击+符号展开一行,导致回调控制器的辅助数据方法。第二个方法将子网格数据作为有效的json返回(我用Google

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

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

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

我已经浏览了在线文档和这里的各种建议,但似乎没有任何效果。我已经使用了相当多的jsonReader配置,但它似乎没有帮助(如果我将repeatitems设置为true,它根本不起作用)。将gridview从true翻转为false似乎也没有帮助

感谢您的帮助

这是对sub-grid controller方法的实际调用:

/Schedule/SubGridData?nd_=1365975664423&id=1002200&InspectionScheduleId=1002200&ItemTypeId=1000003
这是谷歌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>

jQuery(文档).ready(函数(){
jQuery(“#GridDatabase”).jqGrid({
自动编码:正确,
自动宽度:正确,
标题:“检查时间表”,
数据类型:'json',
jsonReader:{repeatitems:false,id:'InspectionScheduleId',子网格:{root:'rows',repeatitems:false,cell:'cell',id:'id'},
emptyrecords:“未找到记录”,
gridview:false,
高度:'100%',
loadui:“块”,
寻呼机:“#寻呼机”,
行列表:[10,15,20,50],
rowNum:10,
rowattr:函数(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){返回{class':'redOffsetColor'};}colorDate=new-Date(dueDate-(rowData.OrangeOffsetInMinutes*60000));if(nowDate>colorDate){return{'class':'orangeOffsetColor'};}colorDate=新日期(dueDate-(rowData.yellowOffsetMinutes*60000));if(nowDate>colorDate){return{'class':'yellowOffsetColor'};}colorDate=新日期(dueDate-(rowData.greenOffsetMinutes*60000));if(nowDate>colorDate){return{'class':'greenOffsetColor'},
viewsortcols:[true、'vertical',true],
shrinkToFit:是的,
url:“/Schedule/IndexGridData”,
viewrecords:是的,
子网格:对,
subGridUrl:“/Schedule/SubGridData”,
子网格模型:[{
名称:['项目名称','项目说明'],
宽度:[50,50],
对齐:['左','左'],
参数:['InspectionScheduleId','ItemTypeId']
} ],
colModel:[
{
名称:'InspectionScheduleId',
隐藏:是的,
关键:没错,
标签:'InspectionScheduleId',
可排序:false,
索引:'InspectionScheduleId'
},{
名称:'ItemTypeId',
隐藏:是的,
标签:'ItemTypeId',
可排序:false,
索引:'ItemTypeId'
},{
名称:'GreenOffsetInutes',
隐藏:是的,
标签:'GreenOffsetInutes',
可排序:false,
索引:'greenoffset分钟'
},{
名称:'YellowOffsetMinutes',
隐藏:是的,
标签:'YellowOffsetingMinutes',
可排序:false,
索引:'YellowOffsetMinutes'
},{
名称:'OrangeOffsetInMinutes',
隐藏:是的,
标签:'OrangeOffsetInMinutes',
可排序:false,
索引:'OrangeOffsetInMinutes'
},{
名称:'RedOffsetInMinutes',
隐藏:是的,
标签:'RedOffsetInMinutes',
可排序:false,
索引:“RedOffsetInMinutes”
},{
名称:'ItemTypeName',
标签:'项目类型',
可排序:false,
索引:'ItemTypeName'
},{
对齐:'居中',
名称:'DueDate',
格式化程序:'date',格式化选项:{srcformat:'ISO8601Long',newformat:'m/d/Y H:i:s'},
标签:'到期日',
可排序:是的,
索引:'DueDate'
}
]
});
});

jsonReader
的subgrid
属性应包含
repeatitems:true
而不是
false
。subgrid
属性的默认值也是就绪的
{root:“rows”,repeatitems:true,cell:“cell”}
。因此,我认为删除
jsonReader
子网格
属性应该可以解决您的问题。

如果给定的函数之一不存在,子网格中的数据也不会显示。因此,如果您输入错误,将显示空行:

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

打字错误:ReloadSbuGrid应该是ReloadSubGrid

所以,就是这样-谢谢。我挂断了让main和sub-grid repeatitems值相同的问题。main-grid在true上失败,但是sub-grid在false上失败。@Tony:不客气!我很高兴,我可以帮助你。在回答关于
jsonReader 我喜欢它的使用是newcommer许多错误的根源。我向trirand发布了实现JSON格式自动检测的建议。这些建议现在是jqGrid的一部分。我将查看subgrid的代码来实现相同的建议。如果您使用jqGrid 4.4.5,您可以尝试删除完整的
jsonReader
。使用中有一个bug对于
loadonce:true
,但您不使用它。因此,我认为如果您只删除
jsonReader
,您的网格将被成功填充。但是,如果我删除jsonReader,我将如何告诉jqGrid我的哪些列表示唯一的行id?我不希望jqGrid使用任意值并在将来的任何定制中传递该值@Tony:在列“InspectionScheduleId”的定义中,您已经使用了
key:true
。它为jaGrid提供了足够的id信息。您可以使用