Solved

Populating JQGrid with C# JSON

Posted on 2011-09-26
2
1,943 Views
Last Modified: 2012-05-12
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","cell":["1","user1","dublin","first user","","17/01/2011 21:37:08"]},
{"id":"2","cell":["2","Administrator","dublin","administrator","15/04/2011 14:15:08","18/02/2011 20:55:24"]}, {"id":"3","cell":["3","user 2","dublin","","13/05/2011 15:18:47","13/05/2011 10:52:03"]}, {"id":"4","cell":["4","user 3","dublin","third user","23/06/2011 17:59:06","15/06/2011 13:51:35"]}, {"id":"5","cell":["5","user 4","dublin","fourth user","","09/08/2010 08:53:49"]} ]}

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>

Open in new window


Many thanks
0
Comment
Question by:itfocus
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 125 total points
ID: 36600432
column names are not the same
0
 

Author Closing Comment

by:itfocus
ID: 36998669
Oops; I didn't spot that at the time.  Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now