I just started working with jqGrid this week. I’m attempting to make a generic function that I can call to load a jqGrid with different postData parameters, defined in the function call.
Is there any way to do this? What I had considered was creating an array to store the parameter’s name/value, then setting that as a parameter in the postData. The web service would then go through and add those parameters to the SQL stored procedure call.
Here is the generic code:
var paramArray = new Array();
var p1 = new JQGridParam("CustomerName","John");
var p2 = new JQGridParam("ProductName","Kleenex");
var p3 = new JQGridParam("YearPurchased","2012");
paramArray[0] = p1;
paramArray[1] = p2;
paramArray[2] = p3;
$("#list").jqGrid({
datatype: "json",
url: "services/Customers.asmx/GetCustomerData",
mtype: "POST",
postData: {
sqlParams: paramArray //HERE IS WHERE I NEED THE HELP
},
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
ajaxRowOptions: { contentType: "application/json; charset=utf-8" },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
serializeRowData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d.rows; },
page: function (obj) { return obj.d.page; },
total: function (obj) { return obj.d.total; },
records: function (obj) { return obj.d.records; },
},
colModel: [
{name: "CustID", index: "CustID" },
{name: "PurchaseAmount", index: "PurchaseAmount" }],
colNames: ["Customer ID", "Amount Purchased"],
pager: $("#pager"),
loadOnce: true,
rowNum: 10,
rowList: [10,25,50],
gridview: true,
viewrecords: true
});
When I try this, it throws the error “cannot convert object of type System.String to type System.Array”. Anyone have any ideas how to go about this?
JSON stringify the array.
Then in your webservice cast the JSON data back to your object.