Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
handle json data with root element
10/12/2009
16:35
Avatar
gsproof
New Member
Members
Forum Posts: 2
Member Since:
10/12/2009
sp_UserOfflineSmall Offline

Hi,

I have a server that returns JSON data for jqgrid in the format with root element, like:

{”data”:{”currPage”:1,”totalPages”:1,”totalRecords”:2,”users”:[{"id":1, name":"x1", email:"e1"},{"id":2,email:"e2"}]}}

I was trying to use the dot notation for root, page, etc, but with no luck.

jsonReader: {
            root: “data.users”,
            page: “data.currPage”,
            total: “data.totalPages”,
            records: “data.totalRecords”,
            repeatitems: false,
            id: “0″
        }

Is that supported?

If not what would be the best path to take?

Thanks.

11/12/2009
14:29
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello

if your output is like this

{”d”:{”currPage”:1,”totalPages”:1,”totalRecords”:2,”users”:[{"id":1, name":"x1", email:"e1"},{"id":2,email:"e2"}]}}

you should not do anything.

I.e not data, but d. jqGrid support the d property generated from some Microsoft products.

Another possible solution is to use a datatype as function , where you can put what you want to the json parser.

See demos.

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.

12/12/2009
09:10
Avatar
Rushi
Guest
Guests

Hello,

I have a similar problem to the above however, the instead of "d", the name coming back from my web service is "ListData". Also, this will change depending on the type of the request. I cannot change the returned string from the web service so I need to handle this somehow on the javascript side.

{"ListData" : {"Success":"true","Record":"1", "rows":[{"MyID" : "7","MyTitle" : "MyTitle","StartDate" : "09.12.2009","EndDate" : "31.12.2009"}]}}

How do I specify the jsonReader so the grid can read the data contained in the rows array? I tried the following with no success:

rows: 'ListData'
rows: 'ListData.rows'

If I populate the grid using addRowData, it works fine but I want to have it autopopulated using the json datatype. I know I am missing something very basic.

Can anyone help me?

Thanks,
Rushi

13/12/2009
18:03
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I suggest you in this case to use datatype as function. The code can look like this

jQuery("#listdt").jqGrid({       
    datatype :     function  (pdata) {
        $.ajax({
            url:'server.php?q=2',
            data:pdata,
            dataType:"json",
            complete: function(jsondata,stat){
                if(stat=="success") {
                    var thegrid = jQuery("#listdt")[0];

                    var resp =  $.jgrid.parse(jsondata.responseText);
                    thegrid.addJSONData(resp.ListData)
                }
            }
        });
    },

...

})

Instead I will think how this 'd' property in parse function to be configurable.

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.

15/12/2009
02:00
Avatar
Rushi
Member
Members
Forum Posts: 6
Member Since:
10/10/2009
sp_UserOfflineSmall Offline

Thanks a lot, Tony. I'll try it out right away. Another question though, will this approach work in case of the "Search Big Sets" example that you have in the demo? I need to display list of records from a database table in the grid but the database table contains over 80,000 records. I was wondering if this approach with the custom datatype function combined with the "Search Big Sets" logic work for such a kind of load. Appreciate your response.

Thanks,

Rushi

15/12/2009
02:32
Avatar
Rushi
Member
Members
Forum Posts: 6
Member Since:
10/10/2009
sp_UserOfflineSmall Offline

Tony,

Another thing: I used the above approach and it seems work fine (although I am waiting to get an answer from you for the "Search Big Sets"). The problem I am facing is I have a loadComplete function tied to the grid and if I use your above suggested approach, my loadComplete function doesn't get called. Am I missing something?

15/12/2009
19:23
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

As you can see - in case of custom datatype you should add your code from loadComplete after addJSONData, or use gridComplete event which is lunched when all data is in the grid.

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
52 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information