Hi,
I'd like to know if it is possible to manage the result that controller action send bakc after a "saveChanges" igGrid called method.
My controller action ends with:
JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); response.Add("Success", true); result.Data = response; return result;
And I know that, if ("Success", true) everything goes right. But if I would like to have more info, or just catch ("Success", false), is there a way to get result in javascript section? Now I have (for example related to deleted row event):
$("#grid1").live('iggridupdatingrowdeleted', function (event, ui) { $("#grid1").igGrid("saveChanges"); });
If I put:
result = $("#grid1").igGrid("saveChanges");
I can see that result is a HTMLTableElement object...is it right? Do you have some suggestions to let me understand how manage saveChanges result or just to manage a negative come back result?Thank you,
Flavio
Hi Flavio,
if you return a JsonResult, the response should be in Json format, and not HTML, could you paste parts of the response (or the whole response) ?
Other than that, if you'd like to can add any number of callbacks to notify you when the response from saveChanges arrives:
$("#grid").data("igGrid").dataSource._addChangesSuccessHandler( <your handler>);
there is also
$("#grid").data("igGrid").dataSource._removeChangesSuccessHandler( <your handler>);
The parameters that will be passed to your function are: data, textStatus, jqXHR.
Hope it helps. Thanks,
Angel
Hi Angel,
sorry for the late answer. It is very good !!! But I am not able to use it...
I just added:
$("#myGrid").data("igGrid").dataSource._addChangesSuccessHandler( test() );
function test(){ // do something}
But for sure I am wrong, because adding a new row just stops and does anything: no written on db and no test method called...Could you explain me better waht you told me in your previous post?Where can I find some documentation or samples about dataSource._addChangesSuccesHandler or something like that?
Thanks
change this:
to this:
$("#myGrid").data("igGrid").dataSource._addChangesSuccessHandler( test);
the handler shouldn't be a function invocation like test(), but the actual reference itself , that is "test" itself - without the quotes.
Hope it helps
This was a sample of my code with a MVC view. The m is the Model instance in a foreach loop - foreach(var m in Model)
<script type="text/javascript"> $(function () { //function that handles the result after the updates $("#Grid_@m.QuotaID").data("igGrid").dataSource._addChangesSuccessHandler(function (data, textStatus, jqXHR) { alert("Request status: " + textStatus); }); }); </script> <script type="text/javascript"> $(function () { //function that handles the result after the updates $("#Grid_@m.QuotaID").data("igGrid").dataSource._addChangesErrorHandler(function (data, textStatus, jqXHR) { alert("Request FAILURE status: " + textStatus); }); }); </script>
Hello - I believe I had the same confusion about this and how to handle the FAILUREs. I would point out that there is the ability to handle the Failure message with a 2nd function when calling the saveChanges method.. See the documentation screenshot
I can answer my own question.
I had this in my code:
$("#TimesheetGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);$("#TimesheetGrid").igHierarcichicalGrid("saveChanges");
which doesn't work. It did save the changes but didn't fire changesSuccessHandler.
I tried this:$("#TimesheetGrid").data("igHierarcichicalGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);$("#TimesheetGrid").igHierarcichicalGrid("saveChanges");
which didn't work either - didn't even save the changes.
I then changed the saveChanges to reference via igGrid instead of igHierarchicalGrid and it worked fine - data saved and changesSuccessHandler called:
$("#TimesheetGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);$("#TimesheetGrid").igGrid("saveChanges");
Sometimes just asking the question presents the answer.
Graeme
Hi
Should this work OK with an igHierarchicalGrid?
I have got it working fine for a normal igGrid but when I use the same technique with a hierarchical grid my equivalent of the "test" function never gets called.
eg this works on my invoice page with igGrid and the function named "changesSuccessHandler" is called:
$("#InvoiceGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);
this does not work on my timesheet page with a igHierarchicalGrid - "changesSuccessHandler" is never called:
$("#TimesheetGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);
Regards,