I have a problem when saving items on my application, items are listed from a table. Everytime I save the updated items , the items tend to loop after saving.
This is my event of the button.
$('#saveEventBTN').click(function (event) {
//EventManager.SaveEventBYApprover();
EventManager.MultipleSave();
event.preventDefault();
});
This one is from the .Change event on the dropdown menu where I can enter the ids in the arrays that I will use for the looping saving transaction.
$("#tableApprovalState" + idEvent + "").change(function (event) {
idApproveStatus = $("#tableApprovalState" + idEvent + "").val();
event.preventDefault();
// Adding the event into an array for multiple selection.
if (idEventMulti.indexOf(idEvent) !== -1)
{
var del = idEventMulti.indexOf(idEvent);
idEventMulti.splice(del, 1);
idApproveStatusMulti.splice(del, 1);
idEventMulti[idEventMulti.length] = idEvent;
idApproveStatusMulti[idApproveStatusMulti.length] = idApproveStatus;
} else {
idEventMulti[idEventMulti.length] = idEvent;
idApproveStatusMulti[idApproveStatusMulti.length] = idApproveStatus;
}
});
This are the functions on my module :
This only loops the global array variable for the ids of the array.
EventManager.MultipleSave = function () {
for (let i = 0; i < idEventMulti.length; i++) {
EventManager.SaveEventBYApprover(idEventMulti[i], idApproveStatusMulti[i]);
}
}
This one is the Ajax call to save:
EventManager.SaveEventBYApprover = function (idevent, ideventstatus) {
$.ajax({
url: "/Modules/SaveEvent",
type: "POST",
data: {
IdEvent: idevent,
IdEventStatus: ideventstatus,
LastModifiedBy: user
},
dataType: "json",
success: function (data) {
$("#successMsg").html("").html(data.msg);
$("#successConfirmModal").modal("show");
searchResultsTable.clear().draw();
EventManager.BindDataTable();
}
});
}
This is how it looks like after the transactions successfully save.
