jqGrid如何避免使用addrowdata

时间:2015-12-02 03:19:48

标签: jquery jqgrid

我有两个表,其中一个包含来自我本地数据库的数据,当我选择表的行并单击批准或结算时,其数据将被复制到我的第二个空表。

我想要做的是检测我的第二个表中是否已经存在选定的行,如果它存在,即使用户单击批准或结算按钮,这些行也不会被复制到第二个表。

我正在寻找jqGrid的某些功能,但看起来没有这样的选择。

enter image description here

然后我试图使用getCol并比较第一个表的选定行的employeeId和第二个表的所有employeeId,但是当我尝试时我没有得到任何值

var rowDataTwo = $("#reportingList").jqGrid('getCol', columnName);
console.log(rowDataTwo);

请问您对这种情况有什么好的建议吗?

以下是我的代码:

var common = {
        basUrl : function (){
            var l = window.location;
            var url =  "/" + l.pathname.split('/')[1] + "/";
            return url;
        },
        init : function(){
            common.validator();
            common.initDialog();
            common.extendJqgrid();
            common.bindEvent();
            common.datePicker();
            common.initButton();
            common.searchGrid();
            common.initGrid();
        },

        initGrid : function() {

            $("#employeeList").jqGrid(
                    {
                        url: "<c:url value='/app/getGrid'/>",
                        colNames : ['id', 'Department', 'Position', 'Employee'],
                        colModel : [
                                 {
                                    name : 'employeeId',
                                    index : 'employeeId',
                                    hidden : true,
                                    key : true
                                 },
                                 {
                                    name : 'department',
                                    index : 'department',
                                    width : 280,
                                    align : "center",
                                 },
                                 {
                                    name : 'position',
                                    index : 'position',
                                    width : 280,
                                    align : "center",
                                 },
                                 {
                                    name : 'employeeName',
                                    index : 'employeeName',
                                    width : 280,
                                    align : "center",
                                 }, 
                         ],
                         idPrefix : "g1_",
                         rowNum : 10,
                         multiselect : true,
                         multiboxonly: true,
                         pager : '#pager3',
                         viewrecords : true,
                         sortname : 'department',
                         sortorder : "asc",
                         search : false,
                         onSelectRow : function(id, status, e){
                             var selectRowId = $("#employeeList").jqGrid('getGridParam', 'selrow');
                             if (selectRowId != null) {
                                $("#btnApprovalCon, #btnSettlementCon, #btnEnforcementCon, #btnReferenceCon").button("option", "disabled", false);
                             } else {
                                $("#btnApprovalCon, #btnSettlementCon, #btnEnforcementCon, #btnReferenceCon").button("option", "disabled", true);
                                var rowData = null;
                             }
                         },
                         onSelectAll : function(rowId, status) {
                            if (status){
                                $("#btnApprovalCon, #btnSettlementCon, #btnEnforcementCon, #btnReferenceCon").button("option", "disabled", false);
                             } else {
                                $("#btnApprovalCon, #btnSettlementCon, #btnEnforcementCon, #btnReferenceCon").button("option", "disabled", true);
                             }
                         },
                         gridComplete : function(){
                             $("#btnApprovalCon").on('click', function(employeeId) {

                                    var rowDataTwo = $("#reportingList").jqGrid('getCol', employeeId);
                                    console.log(rowDataTwo);

                                    var list = $("#employeeList").jqGrid ('getGridParam', 'selarrrow'); //arrayList
                                    if(list != null){
                                        $.each(list, function(i,v){
                                                var rowData = $("#employeeList").jqGrid('getRowData', v);
                                                console.log(rowData);

                                                var data = {appset_employeeId: rowData.employeeId, appset_department: rowData.department, appset_position:rowData.position, appset_employeeName:rowData.employeeName, type:'Approval'}
                                                $("#reportingList").jqGrid('addRowData', rowData.id, data);
                                        });
                                    }
                                });
                             $("#btnSettlementCon").on('click', function(selrow) {
                                    var list = $("#employeeList").jqGrid ('getGridParam', 'selarrrow'); //arrayList(object)
                                    if(list != null){
                                        $.each(list, function(i,v){
                                                var rowData = $("#employeeList").jqGrid('getRowData', v);
                                                console.log(rowData);
                                                var rowCount = $("#reportingList").jqGrid('getGridParam', 'records');
                                                var rowNum = rowCount + 1;
                                                var data = {appset_employeeId: rowData.employeeId, appset_orderNumber: rowNum,  appset_department: rowData.department, appset_position:rowData.position, appset_employeeName:rowData.employeeName, type:'Settlement'}
                                                $("#reportingList").jqGrid('addRowData', rowData.id, data);
                                        });
                                    }
                                });
                         }
                    }).navGrid("#pager3", { search:false, edit:false, add:false, del:false});   

            $("#reportingList").jqGrid(
                    {
                        colNames : ['id', 'Department', 'Position', 'Employee', 'Type'],
                        colModel : [
                         {
                            name : 'appset_employeeId',
                            index : 'appset_employeeId',
                            hidden : true,
                            key : true
                         },
                         {
                            name : 'appset_department',
                            index : 'appset_department',
                            width : 210,
                            align : "center",
                         },
                         {
                            name : 'appset_position',
                            index : 'appset_position',
                            width : 210,
                            align : "center",
                         },
                         {
                            name : 'appset_employeeName',
                            index : 'appset_employeeName',
                            width : 210,
                            align : "center",
                         },
                         {
                            name : 'type',
                            index : 'type',
                            width : 210,
                            align : "center",
                         }, ],
                         idPrefix : "g2_",
                         rowNum : 10,
                         multiselect : true,
                         multiboxonly: true,
                         pager : '#pager4',
                         viewrecords : true,
                         search : false,
                         viewrecords : true,
                         reloadAfterEdit : true,
                         reloadAfterSubmit : true,
                         onSelectRow : function(id, status, e){
                             var selectRowId = $("#reportingList").jqGrid('getGridParam', 'selrow');
                             if (selectRowId != null) {
                                $("#btnAppSetDel").button("option", "disabled", false);
                             } else {
                                $("#btnAppSetDel").button("option", "disabled", true);
                                var rowData = null;
                             }
                         },
                         onSelectAll : function(rowId, status) {
                            if (status){
                                $("#btnAppSetDel").button("option", "disabled", false);
                             } else {
                                $("#btnAppSetDel").button("option", "disabled", true);
                             }
                         },
                         gridComplete : function(){
                            $("#btnAppSetDel").on('click', function(columnName) {

                                var delList = $("#reportingList").jqGrid ('getGridParam', 'selarrrow'); //arrayList(object)
                                if (delList != null) {
                                    $("#reportingList").jqGrid('delRowData', delList);

                                    var rowDataTwo = $("#reportingList").jqGrid('getCol', columnName);
                                    console.log(rowDataTwo);
                                }
                            });
                         }
                    }).navGrid("#pager4", { search:false, edit:false, add:false, del:true});

            $("#reportingList").sortableRows();
            $("#reportingList").jqGrid('gridDnD');
        },

我尝试将reportList的getCol放在#btnApprovalCon点击功能中,但是它不起作用,此时它并不重要,因为我甚至无法在reportingList中获得employeeId的值。

编辑:

gridComplete : function(){
 $("#btnApprovalCon").on('click', function() {

    var list = $("#employeeList").jqGrid ('getGridParam', 'selarrrow'); //arrayList
    if(list != null){
        $.each(list, function(i,v){
            var rowData = $("#employeeList").jqGrid('getRowData', v);
            console.log(rowData);

            var ids = $("#employeeList").jqGrid('getDataIDs');
            console.log(ids);
            var nthIds = ids[i];
            console.log(nthIds);

            var idsTwo = $("#reportingList").jqGrid('getDataIDs');
            console.log(idsTwo);

            var data = {appset_employeeId: rowData.employeeId, appset_department: rowData.department, appset_position:rowData.position, appset_employeeName:rowData.employeeName, type:'Approval'}
            $("#reportingList").jqGrid('addRowData', rowData.id, data);
        });
    }
}

enter image description here

0 个答案:

没有答案