Des Kelly
asked on
Populating JQGrid with C# JSON
Hi,
I have been trying to populate a JQGrid using JSON created by a C# webservice. It is coming back with a status of "success", but no data is appearing in the grid. Below is the data which is being returned from the webservice. Is there something wrong with the format here?
{"total": "5","page": "1","records": "5","rows":[{"id":"1","cel l":["1","u ser1","dub lin","firs t user","","17/01/2011 21:37:08"]},
{"id":"2","cell":["2","Adm inistrator ","dublin" ,"administ rator","15 /04/2011 14:15:08","18/02/2011 20:55:24"]}, {"id":"3","cell":["3","use r 2","dublin","","13/05/2011 15:18:47","13/05/2011 10:52:03"]}, {"id":"4","cell":["4","use r 3","dublin","third user","23/06/2011 17:59:06","15/06/2011 13:51:35"]}, {"id":"5","cell":["5","use r 4","dublin","fourth user","","09/08/2010 08:53:49"]} ]}
The JQuery to populate the grid is:
Many thanks
I have been trying to populate a JQGrid using JSON created by a C# webservice. It is coming back with a status of "success", but no data is appearing in the grid. Below is the data which is being returned from the webservice. Is there something wrong with the format here?
{"total": "5","page": "1","records": "5","rows":[{"id":"1","cel
{"id":"2","cell":["2","Adm
The JQuery to populate the grid is:
<script language="javascript" type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list2").jqGrid({
datatype: function () {
$.ajax({
url: "/webservices/activedirectory.asmx/GetActiveDirectoryUsersJson",
data: '{"GroupName":"test","Filter":""}',
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
complete: function (jsondata, stat) {
if (stat == "success") {
var thegrid = jQuery("#list2")[0];
alert(JSON.parse(jsondata.responseText).d);
thegrid.addJSONData(JSON.parse(jsondata.responseText).d);
}
}
});
},
colNames: ['ID', 'LogonName', 'DomainName', 'Description', 'Last Logon', 'Days Since PW Changed'],
colModel: [
{ name: 'id', index: 'id asc', width: 155 },
{ name: 'LogonName', index: 'logonname asc', width: 155 },
{ name: 'DomainName', index: 'domainname', width: 150 },
{ name: 'Description', index: 'description', width: 200 },
{ name: 'LastLogon', index: 'lastlogon', width: 80, align: "right" },
{ name: 'pwdlastset', index: 'pwdlastset', width: 180, align: "right"}],
rowNum: 15,
rowList: [15, 30, 100],
pager: jQuery('#pager2'),
sortname: 'logonname',
loadtext: "loading data...",
viewrecords: true,
sortorder: "desc",
jsonReader: {
root: "d",
page: function () { return 1; },
total: function () { return 1; },
records: function (obj) { return obj.length; }
}
});
});
</script>
Many thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER