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
jsonReader / reading "nonstandard" JSON
22/07/2011
23:13
Avatar
ronchalant
Philadelphia
Member
Members
Forum Posts: 5
Member Since:
01/04/2011
sp_UserOfflineSmall Offline

Is there a way using the jsonReader or maybe with an event that a JSON object returned from an AJAX call can be translated into something the jqGrid can understand?

We have standard JSON objects gen'd from data model classes that I can return sort of like this:

{

   items: [

{ fname: 'Jon', lname: 'Doe', homeAddress: { address1: '123 Main St.', city: 'Sometown', ... }, status: { id: 1, description: 'active' } },

{ fname: 'Jane', lname: 'Doe', homeAddress: { address1: '123 Main St.', city: 'Sometown', ... }, status: { id: 1, description: 'active' } },

 ...

   ]

}

Which is totally non-conformant... is there a way/place I can inject a function in JS to convert it?  I tried modifying the "success" function of the xhr via the loadBeforeSend(xhr) event, but it didn't like it.

I'm using 3.8.2 for now, btw.

22/07/2011
23:39
Avatar
ronchalant
Philadelphia
Member
Members
Forum Posts: 5
Member Since:
01/04/2011
sp_UserOfflineSmall Offline

I actually found a solution for this - adding ajaxGridOptions to my grid config options and using the dataFilter:

ajaxGridOptions: {
  dataFilter : function(data, type) {
    if (typeof(data) === 'string' && type === 'json') {
      data = jQuery.parseJSON(data);
    }
    return convert(data);
  }
}

the "convert" function takes whatever I received from the AJAX call and converts it to the jqGrid standard with rows / cell / etc.  The interesting thing is that regardless of setting the datatype to JSON it seems to always pass in and want returned a string value.  So I have to parse the JSON string, convert to a new object, then stringify the converted object before returning it.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
48 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