jqGrid addRowData不能与网格一起用作子网格

我想在jqGrid中使用网格作为子网格,因为我读到“简单子网格”不允许单元格编辑。

我正在使用dataType函数成功填充主网格,我正在尝试对子网格执行相同的操作,但是subgrid显示没有数据,我不知道为什么因为我调试并从Web服务正确捕获数据,但是当我通过对子网格执行addRowData的数据似乎没有任何效果。

我正在使用ASP.Net 2.0 Web服务和JSON,这是客户端代码,任何想法:-S? 谢谢 :-)

编辑:

我补充说:

function ReceivedClientData(data) { var thegrid = $("#" + gridId); if ($(thegrid).length == 0) alert('NOT EXISTS'); thegrid.clearGridData(); for (var i = 0; i < data.length; i++) thegrid.addRowData(i + 1, data[i]); } 

并且我收到了子网格的NOT EXISTS,我不知道是否是检查选择器是否存在的最佳方法,但这意味着当我捕获ajax回发时,我找不到jqgrid创建的“动态”? 我怎样才能填充子网格?

编辑2:

我认为我的子网格ID错了,现在我将一个变量保存在grid_id中

 subGridRowExpanded: function(subgrid_id, row_id) { subGridID = subgrid_id; 

并在回调时使用它,但是当我尝试addRowData时,我从jqgrid.js收到p.rownumbers为null。 :-S有什么建议吗?

 function ReceivedClientDataForSubGrid(data) { var thegrid = $("#" + subGridID); if ($(thegrid).length == 0) alert('NOT EXISTS'); thegrid.clearGridData(); for (var i = 0; i < data.length; i++) thegrid.addRowData(i + 1, data[i]); } 

将“编辑3”移动到答案以将问题标记为已回答


我解决了,我正在访问一个不正确的ID,正确的ID是var thegrid = $(“#”+ subGridID +“_ t”);

完整的客户代码

 var gridId = "table"; $(function() { $("#"+gridId).jqGrid({ datatype: function(pdata) { getData(pdata); }, height: 250, colNames: ['Nombre Objetivo', 'Tipo Objetivo', 'Objetivo Tipo 1', 'Objetivo Tipo 2', 'Objetivo Tipo 3', 'Autoevaluacion', 'Resultado Final', 'Actions'], colModel: [ { name: 'ObjetivoNombre', width: 200, sortable: false }, { name: 'TipoObjetivo', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} }, { name: 'ObjetivoTipo1', width: 200, sortable: false, hidden: true }, { name: 'ObjetivoTipo2', width: 200, sortable: false, hidden: true }, { name: 'ObjetivoTipo3', width: 200, sortable: false, hidden: true }, { name: 'Autoevaluacion', width: 200, sortable: false, hidden: false, editable: true }, { name: 'ResultadoFinal', width: 200, sortable: false, hidden: false, editable: true }, { name: 'act', index: 'act', width: 75, sortable: false } ], cellEdit: true, cellsubmit: 'clientArray', pager: '#pager', rowNum: 10, rowList: [10, 20, 30], sortname: 'Nombre Objetivo', sortorder: 'desc', viewrecords: true, gridComplete: function() { var ids = jQuery("#table").jqGrid('getDataIDs'); var idsLength = ids.length; for (var i = 0; i < idsLength; i++) { var cl = ids[i]; de = ""; jQuery("#table").jqGrid('setRowData', ids[i], { act: de }); } }, subGrid: true, subGridRowExpanded: function(subgrid_id, row_id) { var subgrid_table_id; subgrid_table_id = subgrid_id + "_t"; jQuery("#" + subgrid_id).html("
"); jQuery("#" + subgrid_table_id).jqGrid( { datatype: function(pdata) { getDataSubGrid(pdata); }, colNames: ['Nombre Objetivo', 'Tipo Objetivo', 'Objetivo Tipo 1', 'Objetivo Tipo 2', 'Objetivo Tipo 3', 'Autoevaluacion', 'Resultado Final'],//, 'Actions'], colModel: [ { name: 'ObjetivoNombre', width: 200, sortable: false }, { name: 'TipoObjetivo', width: 200, sortable: false, editable: true, edittype: 'select', editoptions: { value: { 1: '1', 2: '2', 3: '3'}} }, { name: 'ObjetivoTipo1', width: 200, sortable: false, hidden: true }, { name: 'ObjetivoTipo2', width: 200, sortable: false, hidden: true }, { name: 'ObjetivoTipo3', width: 200, sortable: false, hidden: true }, { name: 'Autoevaluacion', width: 200, sortable: false, hidden: false, editable: true }, { name: 'ResultadoFinal', width: 200, sortable: false, hidden: false, editable: true } ], height: 100, rowNum: 20, sortname: 'num', sortorder: "asc" }); }, caption: "jQGrid Ejemplo" }) }); //AJAX GET DATA FROM WS function getData(pData) { gridId = "table"; $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: '<%= ResolveClientUrl("~/WebService.asmx/ObtenerDatosDPO") %>', data: '{}', dataType: "json", success: function(data, textStatus) { ReceivedClientData(JSON.parse(getMain(data)).rows); }, error: function(data, textStatus) { alert('An error has occured retrieving data!'); } }); } function getDataSubGrid(pData) { gridId = "table_t"; $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: '<%= ResolveClientUrl("~/WebService.asmx/ObtenerDatosDPOSubGrid") %>', data: '{}', dataType: "json", success: function(data, textStatus) { ReceivedClientData(JSON.parse(getMain(data)).rows); }, error: function(data, textStatus) { alert('An error has occured retrieving data subgrid!'); } }); } //COMMON FUNCTIONS function ReceivedClientData(data) { var thegrid = $("#"+gridId); thegrid.clearGridData(); for (var i = 0; i < data.length; i++) thegrid.addRowData(i + 1, data[i]); } function getMain(dObj) { if (dObj.hasOwnProperty('d')) return dObj.d; else return dObj; }