I have a grid that does the batch update by doing $('#grid').igGrid('saveChanges'). In my controller that handles the save, I followed the sample code to return JsonResult whether it succeed or fail.
Is there an event that the grid dispatch once the save completed ? if so, how do I access that json result status ? I want to do some more logic once the save is done only when the save finished successfully.
Hi Jeffrey,I'm afraid that there is no public API function available for this operation.However, there's an internal method of the igDataSource that you can use without any problems: _addChangesSuccessHandler.Here's an example of how to get the status of the request after it has arrived:
<script type="text/javascript"> $(function () { $("#Grid1").live("iggridrendered", function (evt, ui) { $("#Grid1").data("igGrid").dataSource._addChangesSuccessHandler(function (data, textStatus, jqXHR) { alert("Request status: " + textStatus); }); }); }); </script>
I'm also attaching an MVC3 sample demo'ing the solution.Cheers,Borislav
Borislav,
One follow up question, what is the difference between doing this: $("#Grid1").data("igGrid").dataSource
and this: $('#Grid1').igGrid('option', 'dataSource')
Seems like the first one works better, as I find the second code doesn't always return me the dataSource object.
Ah, good question :)
$('#Grid1').igGrid('option', 'dataSource')
This helps you retrieve the value that you've assigned to the dataSource option of the igGrid - usually your source data.
$("#Grid1").data("igGrid").dataSource
This on the other hand gives you access to the igGrid's internal igDataSource object.I know that may not look like an out-of-the-box solution, but actually you end up accessing internal components of any jQuery UI widget, you end doing so through data().
Cheers,Borislav
Hi Borislav,
I am batching my updates back to the server and in the event where some of my records fail server side validations(lets say 2 out of 10 modified records), i am doing a rollback and sending the JSON response like mentioned in the sample: https://www.igniteui.com/grid/basic-editing.
At this point none of the records are committed back to the server. My problem is after user corrects the validation error(for the two records), and saves, only the 2 correct records are there in the transactionlist...
List<Transaction<ResultMetaData>> transactions = m.LoadTransactions<ResultMetaData>(HttpContext.Request.Form["ig_transactions"]);
Though the gird shows the changes, I am unable to access the other 8 records in my controller.
Please advice if you need more details/clarifications and suggest how I can handle failed cases when batching my updates.
Thank You,
Hari
No prob, Jeffrey :)If you need help with anything else, just let us know.Cheers,Borislav
Cool.. didn't realize that .data() is actually a jquery function. Thanks for the explanation.
Jeffrey