[ 3 posts ]

Abe

  • Username: abe.park
  • Joined: Fri Nov 20, 2009 4:04 pm
  • Posts: 13
  • Offline
  • Profile

Using mismatched DataSource/JSON and DataTable Column Def

Post Posted: Fri Apr 09, 2010 10:22 am
+0-
I have a XHRDataSource that uses JSON as the response type and with responseSchema that has 6 fields.

My DataTable will only have 4 columns, but for one of the columns, I want to use 3 of the properties from the returned JSON object.
Any suggestions on going about this?

I would rather keep the existing JSON responseSchema, if possible.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Using mismatched DataSource/JSON and DataTable Column De

Post Posted: Fri Apr 09, 2010 10:39 am
+0-
That is fine, the number of fields in the responseSchema and those in the column definitions don't need to match, that is why you have to provide those same names twice, they are not the same.

In your custom formatter you can use the Record object to fetch the value of any of the other fields by name using method getData:

oRecord.getData('otherField');

The fields will show up by the name they were given in the responseSchema.

Abe

  • Username: abe.park
  • Joined: Fri Nov 20, 2009 4:04 pm
  • Posts: 13
  • Offline
  • Profile

Re: Using mismatched DataSource/JSON and DataTable Column De

Post Posted: Fri Apr 09, 2010 5:22 pm
+0-
Thank you Satyam!

Your suggestion is what I was looking for and it works for me.
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
cron