In my MVC3 Application I am using a controller actionresult to return two sets of Json data to pass to two separate jqGrids in my view.
The return of the controller’s actionresult looks like:
return Json(new
{
A= holderA,
B= holderB
},JsonRequestBehavior.AllowGet);
Where A and B are arrays of data that were obtained from LINQ to SQL queries.
I have to jquery jqGrids in my View, and the first one should accept the data from “Part A” of my result, and the second grid should accept the data from “Part B” of my result.
I need to know how to access each individual component of my actionresult (i.e. A and B) in jqGrid, is there a specific option that allows your to reference where the data is coming from?
If it helps here is what one grid looks like…
jQuery("#GridA").jqGrid({
url: "/MyController/MyActionresult",
datatype: 'json',
postData: {
Name: function () {
return $("#Name").val();
},
Year: function () {
return $("#SelectedYear").val()
}
},
mtype: 'POST',
colNames: ['Name', 'Age', 'Total']
colModel: [
{ name: 'Name', index: 'Name', align: 'left' },
{ name: 'Age', index: 'Age', align: 'left' },
{ name: 'Total', index: 'Total', width: 150, align: 'left', search: false }],
pager: jQuery('#GridAPager'),
rowNum: 250,
height: 250,
rowList: [250, 500, 1000, 2000],
sortname: 'Name',
sortorder: "asc",
viewrecords: true,
hiddengrid: false,
caption: 'List of People',
gridComplete: function () {
onGridComplete("#GridA");}
});
$("#GridA").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true });
});
And the second grid is almost identical with slightly different fields being displayed.
The reason I would prefer to pass both data sets back from one actionresult is because both grids are being populated once a form submit button is clicked.
Any help would be great,
Thanks.
It’s important to know the exact format of the data in
holderAandholderB. You should define jsonReader which correspond the data structure.You should understand that if you would uses the option
mtype: 'POST'the returned data could not be cached and for filling of “#GridA” and “#GridB” different requests will be done. So you will have no advantage from combining of two responses in one Action.Moreover if the user click for example on the column header of column ‘Name’ of “#GridA” one more request will be send to the URL
"/MyController/MyActionresult". In the request the value of parametersordwill be “desc” instead of “asc” in the initial request. New requests to the server will be send also if the user change the page size from 250 to 500 or if the user change the page which need be displayed.I tried to explain that it has sense to have separate actions for all grids which you have on the page. The combining all in one have not so much sense if not all data will be displayed and if you have server side sorting and paging implemented.