jqGrid addRowData不适用于作为子网格的网格 [英] jqGrid addRowData doesn't work with grid as subgrid

查看:92
本文介绍了jqGrid addRowData不适用于作为子网格的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use a grid as subgrid in jqGrid because I read that "simple subgrid" doesn't allow cell edit.

我成功地用dataType函数填充了主Grid,并且试图对subgrid进行同样的操作,但是subgrid显示了没有数据,并且我不知道为什么,因为我调试了并且我从Web服务中正确地捕获了数据,但是当我查看数据时,对子网格执行addRowData似乎没有任何作用.

I'm filling main Grid with dataType function successfully and I'm trying to do the same for subgrid, but subgrid shows without data, and I don't know why because I debugged and I catch data correctly from web service, but when I go through the data doing a addRowData to the subgrid seems to have no effect.

我正在使用ASP.Net 2.0 Web服务和JSON,这是客户端代码,有什么主意:-S?谢谢:-)

I'm using a a ASP.Net 2.0 web service and JSON,Here is the client code, any idea :-S? Thanks :-)

我添加了一个:

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]);   
}

我收到一个关于subgrid的NOT EXISTS消息,我不知道是否是检查选择器是否存在的最佳方法,但这意味着我在捕获ajax时找不到jqgrid创建的动态"回发?如何填充子网格?

And I receive a NOT EXISTS for subgrid, I don't know if is the best way to check if a selector exists but this would mean that I can't find "the dynamic " created by jqgrid when I capture the ajax postback? How can I fill the subgrid?

我认为我的子网格ID不对,现在我将grid_id保存在变量中

I think that I was wrong with subgrid ID, now I'm saving in a variable the grid_id

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

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

and using it when callback, but I'm receiving a p.rownumbers is null from jqgrid.js when I try to addRowData. :-S any suggestions?

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"移至答案以将问题标记为已回答

Moving the "Edit 3" to an answer to mark the question as answered

我解决了这个问题,我使用了错误的ID,正确的ID是var thegrid = $(#" + subGridID +"_t");

I solved it, I was accesing to an incorrect ID, the correct ID is var thegrid = $("#" + subGridID + "_t");

完整的客户端代码

complete client code

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 = "<input style='height:22px;width:20px;' type='button' value='D' onclick=\"deleteRow('" + cl + "');\" />";
                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("<table id='" + subgrid_table_id + "' class='scroll'></table>");
            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;
    }

这篇关于jqGrid addRowData不适用于作为子网格的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆