I want to perform CRUD operations in the grid. I want to do individual updates and do not want to commit the grid on client side until the CRUD operations have taken place in the database successfully. So when deleting a row in the grid
$('body').on('iggridupdatingrowdeleted', '#grid', function () {
$('#grid').igGrid("saveChanges")
if (SuccessfulUpdate)
{
$('#grid').igGrid("commit");
}
else
// Do not commit
});
How can I check for successful DB update here?
I think I can do something like this too...
Call the "saveChanges" method that invokes a AJAX request to updateURL Action method. This method returns the JSON Result like this:
JsonResult result = new JsonResult();
Dictionary<string, bool> response = new Dictionary<string, bool>();
if (dbResult) response.Add("Success", true); else response.Add("Success", false);
result.Data = response; return result;
The grid changes were committed if a Success=true JSON result was returned.
Hello Anonymous,
Thank you for posting in our community.
By design transactions created for CRUD operations are kept locally in the browser. In order to make a POST request and send these changes to the server you will have to commit and call saveChanges method afterwards. This will invoke an AJAX request to the updateUrl option(if set) and pass the serialized transaction log as a part of the POST request. Basically, this means that currently it is not possible to update the data base without committing changes first on the client side.
In case that error is thrown what I can suggest is handling the error callback of the saveChanges method and data bind igGrid in this handler. For example:
// Save changes with success and error callbacks$(".selector").igGrid("saveChanges", function (data) { $("#message").text("Changes were saved successfully").fadeIn(3000).fadeOut(5000);},function(jqXHR, textStatus, errorThrown) { $("#message").text("An error occurred while saving the changes. Error details: " + textStatus).fadeIn(3000).fadeOut(5000); $(".selector").igGrid("dataBind");});
// Save changes with success and error callbacks$(".selector").igGrid("saveChanges", function (data) { $("#message").text("Changes were saved successfully").fadeIn(3000).fadeOut(5000);},function(jqXHR, textStatus, errorThrown) { $("#message").text("An error occurred while saving the changes. Error details: " + textStatus).fadeIn(3000).fadeOut(5000);
$(".selector").igGrid("dataBind");});
I hope you find my information helpful.
Please let me know if you have any additional questions regarding this matter.