Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
igHierarchicalGrid - how to use _addChangesSuccessHandler to process save JSON result from MVC controller method?
posted

Hi

I had been adding to the following post (which relates to igGrid) but I think that I have a problem specific to igHierarchicalGrid so have started a new post:

http://ko.infragistics.com/community/forums/p/66850/432682.aspx#432682

I have an MVC 4 website running with ignite ui 13.1. My save button invokes a controller method which returns a JSON result, as described in the above post:

The controller save method ends like this:

Dictionary<string, object> response = new Dictionary<string, object>();
string strResponseMessage = string.Empty;
JsonResult result = new JsonResult();

if (strSaveResult.Length == 0)
{
response.Add("Success", true);
result.Data = response;
}
else
{
response.Add("Success", false);
response.Add("ErrorMessage", strResponseMessage);
}
result.Data = response;
return result;

I am using the igHierarchical grid bound to a dataset with two tables in a parent/child relationship.

The problem is that I can't seem to save my data and process the success/error message via a call to changesSuccessHandler. I can save my data or call changesSuccessHandler but I can't do both.

changesSuccessHandler is a javascript function in the view. The following code snippets are behind my save button's click event.

Lines like "$("#TimesheetGrid").igHierarchicalGrid("saveChanges");" call the save method in my controller (apart from in my first example with which no save happens at all - scripting error).

eg:

This does not work at all - my save processing does not invoke and throws an error:
$("#TimesheetGrid").data("igHierarchicalGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);
$("#TimesheetGrid").igHierarchicalGrid("saveChanges");

I get this in the browser console for this error, which makes me think that for some reason I can't add the success handler to a hierarchical grid:

Uncaught TypeError: Cannot call method '_addChangesSuccessHandler' of undefined VM132:3
$.bind.click VM132:3
f.event.dispatch jquery-1.7.1.min.js:3
h.handle.i

This saves changes to my lower band but does not fire changesSuccessHandler:

$("#TimesheetGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);
$("#TimesheetGrid").igHierarchicalGrid("saveChanges");

This fires changesSuccessHandler but DOES NOT save the changes to my lower band of data:
$("#TimesheetGrid").data("igGrid").dataSource._addChangesSuccessHandler(changesSuccessHandler);
$("#TimesheetGrid").igGrid("saveChanges");

It feels like the changesSuccesSHandler callback only works for igGrid ie the first, top level, band in my data so I must be missing something here.

I am at a loss as to what to try next. I am using the changesSuccessHandler to display success or error messages depending upon what happens in the save.

Regards,

Graeme