-
3 Nov 2010 10:07 PM #1
Mapping Json data to a grid with a different set of columns
Mapping Json data to a grid with a different set of columns
I am working on a project in which I need to get a list of Json objects from a web service and use them to populate a grid that contains some of the fields in the Json objects as columns and also contains some columns in which the contents are derived by computing different values that are based on values of fields in the Json objects. It is similar to the Json Grid demo example, but in the demo the grid columns seem to match the fields in the Json objects one to one.
What is the best way to map the values in fields of Json objects to a different set of values? Are there provisions in the JsonReader class or the classes it uses to map the values differently, or does it work better to read the Json objects directly into a ListStore and then work out a mapping when populating the grid from the ListStore? Or is the best way to do this different from either of those alternatives? Thanks.
-
4 Nov 2010 2:17 AM #2
I dont fully understadn what you are looking for, but your JsonReader should read all the fields that your server sends to you. Than your grid columns can use GridCellRenderes where you can access any stored value and do anyting needed with it.
-
5 Nov 2010 3:05 PM #3
Here’s what I’m trying to do:
First of all, the code I’m working with is passed a JSON string that was obtained by a call to RequestBuilder’s sendRequest function. I’d like to use JsonReader or JsonLoadResultReader to work with the contents of that JSON string, but your Json Grid demo shows a situation in which the RequestBuilder object is included in an HttpProxy object that in turn is used by a BaseListLoader object to get the JSON string and store it in a ListStore object without exposing the JSON string. I don’t understand how to use the constructor and other functions of the JsonReader class when I already have a JSON string that I want to store the contents of in the same way as is done in the Json Grid example.
So my first question is, is it possible to pass a JSON string in to a JsonReader object in order to get its contents into a ListStore, and if so, how?
Suppose my JSON string looks like this:
and I want to put the data that I obtain into a grid that has columns named “Name”, “At Bats”, “Hits” and “Batting Average”. The values in the “Name” column should be firstName + “ “ + lastName, and the values in the “Batting Average” column should be hits / atBats.Code:{"players":[ {"firstName":”Fred”,"lastName":"Smith","atBats":230,"hits":77}, {"firstName":”Joe”,"lastName":"Brown","atBats":410,"hits":107}, …. }],"numberOfPlayers":40}
My second question is, What is the best way to map the data from the JSON string to the grid columns in a case like this where some conversion is needed? Should I define a ModelType object whose fields match those of the JSON string and a ColumnModel whose list of ColumnConfig objects matches the columns of the grid and then map them somehow after having read the JSON string into a ListStore using that ModelType in the JSonReader? If so, what classes are there that support this kind of mapping? Or is it better to read the JSON string contents straight into a data structure that represents the columns of the grid -- And if so, how do you do that?
Thanks for your help.
Similar Threads
-
Nested JSON data and JsonStore mapping question
By xsikal in forum Ext 3.x: Help & DiscussionReplies: 8Last Post: 18 Jun 2010, 7:30 AM -
Record mapping data from JSON in form panel
By richardwyke in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 18 Jul 2009, 8:38 AM -
PHP JSON Data Mapping & Search the data
By saravanan.sbm in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 27 Apr 2009, 10:57 PM -
Ext.data.Store won't load with a particular JSON mapping
By shay2501 in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 22 Oct 2008, 1:38 PM -
Mapping data model to JSON and loading forms/grids
By cocorossello in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 28 Feb 2008, 8:16 PM


Reply With Quote