简体   繁体   English

在JqGrid中处于编辑模式时,检索单元格的值

[英]Retrieve value of cells, when in edit mode in JqGrid

Iam using JqGrid to for data entry. 我使用JqGrid进行数据输入。

Iam showing an empty jqgrid at page load and on click of a button, add an empty row from client-side only. Iam在页面加载时显示一个空的jqgrid,单击按钮时,仅从客户端添加一个空行。

On click of the empty row, it becomes editable and the new values can be added. 单击空行后,它变为可编辑状态,并且可以添加新值。

Any number of rows can be added and edited and all rows are in edit mode. 可以添加和编辑任意数量的行,并且所有行都处于编辑模式。

Now I need to get all this data and send it at once to the action in my controller. 现在,我需要获取所有这些数据并将其立即发送到控制器中的操作。

JqGrid provides methods to retrieve row or cell data when not in edit mode. JqG​​rid提供了不在编辑模式下检索行或单元格数据的方法。

But while in edit mode, there's no way given. 但是在编辑模式下,没有任何办法。

I have done the following which works for me but am not sure as to if this is the right way to do it. 我做了以下对我有用的事情,但是不确定这是否是正确的方法。

$("#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++;
            }
        }
});

I know the above code seems shabby, dirty, unprofessional, whatever you wanna call it. 我知道上面的代码似乎简陋,肮脏,不专业,无论您想称它什么。 But works exactly how i want. 但是,正是我想要的。

But if any of you guys have a better idea please let me know 但是,如果你们有更好的主意,请告诉我

Call editLink function for get the value of cells in jqgrid. 调用editLink函数以获取jqgrid中单元格的值。 Write formatter: editLink at colModel of providerId. 编写formatter: editLinkcolModelformatter: editLink In editLink function rowdata.providerName shown a value of ProviderName and rowdata.description shown a value of Description in alert popup. editLink功能rowdata.providerName所示的ProviderName的值和rowdata.description显示在一个说明的值alert弹出。 These values are shown when jggrid loads. 这些值在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>";
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM