Forum


07:30

16/10/2009

Hi,
I'm trying to get a jqGrid to update programmatically with JSON retrieved data, but not having much luck.
I can get data to load fine if I choose datatype: "json" - this works and the grid displays as it should. However, if I manually load the data from the same URL and decode the JSON into an object, with the following:
gdCustomers.jqGrid({
url: "jqGrid.aspx?CallbackTarget=Proxy&Method=GetCustomerList",
editurl: "jqGrid.aspx?CallbackTarget=Proxy&Method=UpdateCustomerRow",
datatype: "clientside",
colNames: ["Name", "Company", "Entered"],
colModel: [
{ name: "Name", index: "Name", width: 150, editable: true, edittype: "text" },
{ name: "CompanyName", index: "CompanyName", width: 200, editable: true },
{ name: "Entered", index: "Entered", width: 75, editable: true, datefmt: "MM/dd/yyyy" }
],
sortname: "Company",
rowNum: 14,
viewrecords: true,
sortorder: "asc",
caption: "Northwind Customer List",
width: 800,
height: 308,
pager: "#gdCustomersPager",
ondblClickRow: function(id) {
gdCustomers.restoreRow(lastSel);
gdCustomers.editRow(id, true);
lastSel = id;
}
}).navGrid("#gdCustomersPager");
Proxy.GetCustomerList(function(custList) {
alert(custList); // object is in right format
gdCustomers.addJSONData(custList);
});
Specifically the problem is that addJSONData(custList) in this case doesn't do anything. No error, no message but the grid also doesn't receive the data.custData isn't JSON but it's an object, but according to the sample in the docs this is what is expected here I think (ie. an object instance rather than a JSON string - the name of the method is rather inaccurate if it's the former).
The only way I can get the data in under program control is by looping through the rows manually and then explicitly using addRowData.
While the latter works i can't seem to provide the necessary paging information (total pages, and total record count) to the grid so paging doesn't work properly.
How do I get jqGrid to load under program control using the same data that the direct JSON link uses?
TIA,
+++ Rick ---
06:42

Moderators
30/10/2007

Hello Rick,
Could you please try with this:
Proxy.GetCustomerList(function(custList) {
alert(custList); // object is in right format
gdCustomers[0].addJSONData(custList);
});
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
78 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66