Jquery jqGrid如何避免使用addrowdata添加重复行
我有两个表,其中一个表包含来自本地DB的数据,当我选择表中的行并单击“批准”或“结算”时,其数据将复制到第二个空表中 我要做的是检测所选行是否已经存在于第二个表中,并且如果它存在,即使用户单击“批准”或“结算”按钮,这些行也不会复制到第二个表中 我一直在寻找jqGrid的某些函数,但似乎没有这样的选项 然后我尝试使用getCol并比较第一个表的选定行的employeeId和第二个表的所有employeeId,但尝试时没有得到任何值Jquery jqGrid如何避免使用addrowdata添加重复行,jquery,jqgrid,Jquery,Jqgrid,我有两个表,其中一个表包含来自本地DB的数据,当我选择表中的行并单击“批准”或“结算”时,其数据将复制到第二个空表中 我要做的是检测所选行是否已经存在于第二个表中,并且如果它存在,即使用户单击“批准”或“结算”按钮,这些行也不会复制到第二个表中 我一直在寻找jqGrid的某些函数,但似乎没有这样的选项 然后我尝试使用getCol并比较第一个表的选定行的employeeId和第二个表的所有employeeId,但尝试时没有得到任何值 var rowDataTwo = $("#reportingL
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');
},
决不能在
gridComplete
中进行事件绑定。您将有多个绑定,而不是一次绑定。我个人从来不使用gridComplete
。好久不见:)。我使用gridComplete是因为如果我将事件绑定放在它的外部,当我单击“批准/结算”按钮时,它会在底部表格中打印两次所选行。先生,我添加了var id=$(“#employeeList”).jqGrid('GetDataId');控制台日志(ids);var nthIds=ids[i];console.log(nthIds);然后我得到[“EMP002”、“EMP004”、“EMP001”、“EMP003”]和EMP002作为id和nthid。问题是无论我选择什么,nthIds始终是第一项的Id:EMP002。我可以问你为什么会这样吗?我以为我是所选行的值。对不起,我不确定您要实现什么。您的代码包含太多错误。例如,您使用$(“#btnApprovalCon”)。在('click',函数(employeeId){…}
或$(“#btnAppSetDel”)。在('click',函数(columnName){…}
。为什么您希望事件单击的参数将是某个元素的id或列名。事件处理程序将由jQuery调用,并且它始终使用对象作为参数。更多示例:您使用了错误的参数。如果您在JSFIDLE中准备演示会更好,因为JSFIDLE更易于MIDI。
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);
});
}
}