How can I send the igGrid datasource to the Controller action MVC 3?
Thanks
Hi,
is there any reason you would like to post the whole data source to the server? If you would like to only send the changed data, you can use the transaction api of the data source / grid.
Otherwise, if you would like to send the whole datasource, here is one way to do this:
var dataSource = $("#grid").data("igGrid").dataSource.data();
$.ajax({ type: 'POST', url: <your controller URL>, data: dataSource, success: successCallback, dataType: "json" });
Hope it helps. Thanks,
Angel
I tried your suggestion, but when the message gets to the server is said undefined. Do you know why the message is undefined?
var dataSource = $('#grid1').data('igGrid').dataSource.data();
$.ajax({ type:
});
I think the problem is that I need to convert the datasource (array of objects) to json array. How do I get the datasource in json format?
in what format is the data you are passing? the $.post / $.ajax expects array of javascript objects. it will do the serialization for you.
Thanks,
yes sounds correct. Thanks
The datasource is json, but for some reason when I called the grid datasource.data() it returns an array of objects. I can see the array of object in google chrome javascript console.
I was able to get the data to the server using the following line of code. The trick was to use JSON.stringfy function, which is the same function that the grid uses when calling savechanges.
$.ajax({ url:
"/SaveGridData/", data: JSON.stringify(dataSource), type: 'POST', contentType: "application/json, charset=utf-8", dataType: "json"
Please let me know if this sounds correct to you.
Thank you so much for your help.