I found the issue is related to grid.commit not being triggered when the row is returned from the server. This causes the recIndx to not be updated. Are there certain conditions that would cause commit to not be triggered? Possibly related to the colModel? I have another pqGrid with the same change code and it works flawlessly. The only major difference between the two grids is the colModel.
This is my change code related to commit:
change: function (evt, ui) {
console.log(ui.source);
if (ui.source == 'commit' || ui.source == 'rollback') {
return;
}
console.log(ui);
var $grid = $(this),
grid = $grid.pqGrid('getInstance').grid;
var rowList = ui.rowList,
recIndx = grid.option('dataModel').recIndx,
addList = [],
updateList = [],
deleteList = [];
for (var i = 0; i < rowList.length; i++) {
var obj = rowList[i],
rowIndx = obj.rowIndx,
newRow = obj.newRow,
type = obj.type,
rowData = obj.rowData;
if (type == 'add') {
var valid = grid.isValid({ rowData: newRow, allowInvalid: true }).valid;
if (valid) {
addList.push(newRow);
}
}
else if (type == 'update') {
var valid = grid.isValid({ rowData: rowData, allowInvalid: true }).valid;
if (valid) {
if (rowData[recIndx] == null) {
addList.push(rowData);
}
else {
updateList.push(rowData);
}
}
}
else if (type == 'delete') {
if (rowData[recIndx] != null) {
deleteList.push(rowData);
}
}
}
if (addList.length || updateList.length || deleteList.length) {
var passBack = JSON.stringify({
addList: addList,
updateList: updateList,
deleteList: deleteList
});
$.ajax({
async: true,
url: "EquipmentListWS.asmx/BatchGridEQL",
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ list: passBack }),
success: function (changes) {
var jsonData = JSON.parse(changes.d);
//Uncomment following logs for code development
console.log(JSON.parse(passBack));
console.log(jsonData);
//commit the changes
grid.commit({ type: 'add', rows: jsonData.addList });
grid.commit({ type: 'update', rows: jsonData.updateList });
grid.commit({ type: 'delete', rows: jsonData.deleteList });
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
},