I have looked up a lot of posts regarding this but still cant figure out how to send the data source to controller (instead of applied filters to the grid). Instead of querying the repository again in the back end I would like to receive the jQGrid data source in the MVC Controller.
I need to somehow get the datasource as a collection in the controller so I can export it to CSV file.
I have defined the following button in jqgrid and next block of code are the properties of the jQgrid I'm setting. I don't know how can I pass the jQgrid's current datasource(filters applied) to the MVC controller.
$("#btnExportCsv").click(function () {
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
color: '#fff'
}, message: '<h1>Exporting to CSV</h1><p><img src="/cms/themes/cm-blue/img/busy.gif" /></p>'
});
generating = true;
$.ajax({
type: 'POST',
dataType: 'json',
url: exportCsvUrl,
error: function (XMLHttpRequest, textStatus, errorThrown) {
$.jGrowl(XMLHttpRequest.responseText, { header: 'Error exporting csv' });
generating = false;
},
complete: function () {
$.unblockUI();
},
success: function () {
growl("Export completed successfully", "Export to Csv");
}
});
});
-----------------------------------
jQGrid params:
$("#myGrid").jqGrid({
colNames: [
.
.
.
],
colModel: [...]
mtype: 'POST',
datatype: 'json',
pager: '#crPager',
page: defaultGridParams.Page,
sortname: defaultGridParams.SortName,
sortorder: defaultGridParams.SortOrder,
rowNum: 10,
rowList: [10, 20, 50, 100],
url: Controllers/control,
height: 'auto',
loadui: 'block',
width: 1200,
caption: sGridCaption,
hidegrid: false,
viewrecords: true,
ShrinkToFit: false,
.
.
.