Forum
11:46
13/05/2011
Hi,
I'l unabled to populate a jqgrid with json data :
the data :
{ "total": "1","page": "1","records": "9","rows":[ { "id": 1,"cell":[ "1","Davolio","Nancy","F"]}, { "id": 2,"cell":[ "2","Fuller","Andrew","F"]}, { "id": 3,"cell":[ "3","Leverling","Janet","F"]}, { "id": 4,"cell":[ "4","Peacock","Margaret","F"]}, { "id": 5,"cell":[ "5","Buchanan","Steven","F"]}, { "id": 6,"cell":[ "6","Suyama","Michael","M"]}, { "id": 7,"cell":[ "7","King","Robert","M"]}, { "id": 8,"cell":[ "8","Callahan","Laura","M"]}, { "id": 9,"cell":[ "9","Dodsworth","Anne","M"]} ]}
the script :
function Button1_onclick() { jQuery(document).ready(function () { $('#liste').jqGrid({ datatype: function () { $.ajax({ url: "WS.asmx/ListeEmployes", data: "{}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", complete: function (jsondata, stat) { if (stat == "success") { var thegrid = jQuery("#liste")[0]; var datajson = JSON.parse(jsondata.responseText).d; thegrid.addJSONData(datajson); alert(datajson); } } }); }, colNames: ['EmployeeID', 'LastName', 'FirstName', 'empSex'], colModel: [ {name: 'EmployeeID', index: 'EmployeeID',width: 200}, {name: 'LastName', index: 'LastName', width: 200}, {name: 'FirstName', index: 'FirstName', width: 200}, {name: 'empSex', index: 'empSex', width: 100, align: 'center'} ], pager: jQuery('#pager'), rowNum: 10, rowList: [10,20,30], sortname: 'EmployeeID', sortorder: "desc", viewrecords: true, imgpath: 'images', caption: 'My first grid', jsonReader: { page: "page", total: "total", root: "rows", id: "id", records: "records", repeatitems: false, cell: "cell" }, }).navGrid("#pager", { edit: true, add: true, del: true }); }); }
the grid is well formated but empty.
I can manually load data in the grid with this script bellow :
jQuery("#a4").click(function () { var datarow = { EmployeeID: "10", LastName: "test LN", FirstName: "test FN", empSex: "M" }; jQuery("#liste").jqGrid('addRowData', 99, datarow); });
can you tell what I'm doing wrong,
regards
13:15
10/08/2009
You use wrong template code to implement the jqGrid with respect of datatype which is a function. It was needed for very very old versions of jqGrid. jqGrid supports many parameters which allow you to get JSON data from practicaty any sever inclusive ASMX web services.
In the answer for example you will find full working code which shows how you to use ASMX to provide the data for jqGrid.
Best regards
Oleg
16:45
10/08/2009
What do you mean under "I've try to follow the sample without success". Could you download the example, compile and run it? Is it work? What problems you had? You should understand this to be able to use jqGrid.
The list of disadvantagis of addJSONData is long. Look at here for example. The method addJSONData don't throw any error like all other methods. If you want to see errors you have to implement loadError event handler.
Best regards
Oleg
13:13
Moderators
30/10/2007
Hello,
I'm tottaly confused on what you try to do.
Regards
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:
42 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