【问题标题】:Retrieve value of cells, when in edit mode in JqGrid在 JqGrid 中处于编辑模式时检索单元格的值
【发布时间】:2014-02-14 13:28:04
【问题描述】:

我正在使用 JqGrid 进行数据输入。

我在页面加载和单击按钮时显示一个空的 jqgrid,仅从客户端添加一个空行。

点击空行后,它变成可编辑的并且可以添加新值。

可以添加和编辑任意数量的行,并且所有行都处于编辑模式。

现在我需要获取所有这些数据并立即将其发送到我的控制器中的操作。

JqGrid 提供了在不处于编辑模式时检索行或单元格数据的方法。

但是在编辑模式下,没有办法。

我已完成以下对我有用的操作,但不确定这是否是正确的方法。

$("#btnSave").click(function () {

        var rows = new Array();

        //rows[0] = new Array();
        //Gets total count of records shown currently
        var totalrec = jQuery("#rowed2").jqGrid('getGridParam', 'reccount');

        //total number of columns, 
        //can also use"jQuery("#rowed2").jqGrid('getGridParam', 'colModel').length"
        var totalCol = 4;

        var totalCells = 0;

        for (var i = 0; i < totalrec; i++) {
            rows[i] = new Array();
            for (var j = 0; j < 4; j++) {
                rows[i][j] = jQuery('#rowed2').contents().children().children().children()[totalCells].value;
                totalCells++;
            }
        }
});

我知道上面的代码看起来很破旧、肮脏、不专业,不管你怎么称呼它。但完全符合我的要求。

但如果你们有更好的主意,请告诉我

【问题讨论】:

  • 你试过jQuery("#rowed2").jqGrid('getGridParam','data')吗?
  • 是的,我试过了,但它没有在编辑模式下提供数据。

标签: javascript jquery jqgrid


【解决方案1】:

调用editLink函数获取jqgrid中单元格的值。将formatter: editLink 写入providerId 的colModel。在 editLink 函数中,rowdata.providerName 显示了 ProviderName 的值,rowdata.descriptionalert 弹出窗口中显示了 Description 的值。这些值在 jggrid 加载时显示。

$(document).ready(function(){
        //jqGrid
        $("#providerList").jqGrid({
            url:'<%=request.getContextPath() %>/Admin/getProvidersList',
            datatype: "json",               
            colNames:['Id','Edit','Provider Name','Description','Website','Active','Modified Date'],
            colModel:[
                {name:'providerId',search:false,index:'providerId',hidden:true},
                {name:'providerId',search:false,index:'providerId', width:30,sortable: false, formatter: editLink},
                {name:'providerName',index:'providerName', width:200},
                {name:'description',index:'description', width:210},
                {name:'website',index:'website'},
                {name:'isActive',index:'isActive', width:60,},
                {name:'modifyDate',index:'modifiedDate', width:80,},],
                rowNum:20,
                rowList:[10,20,30,40,50],
                rownumbers: true,  
                pager: '#pagerDiv',
                sortname: 'providerName',  
                viewrecords: true,  
                sortorder: "asc",  
        }); 
        $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
        $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .65);
        $('#load_providerList').width("130");   
        $("#providerList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false},{},{},{}, {closeAfterSearch:true});
        $(".inline").colorbox({inline:true, width:"20%"});
    });
    function editLink(cellValue, options, rowdata, action)
    {
        alert('ProviderName: '+ rowdata.providerName);
        alert('Description: '+ rowdata.description);
        return "<a href='<%=request.getContextPath()%>/Admin/editProvider/" + rowdata.providerId + "' class='ui-icon ui-icon-pencil' ></a>";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 2010-12-19
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多