[ 1 post ]

Todd Smith

YUI Contributor

  • Username: stlsmiths
  • Joined: Thu Nov 05, 2009 10:03 am
  • Posts: 675
  • GitHub: stlsmiths
  • Gists: stlsmiths
  • IRC: t_smith
  • Offline
  • Profile

YUI 3 DataTable with DataSource.Get and callback

Post Posted: Wed Nov 16, 2011 2:22 pm
+1-
I'm slowly starting to transition some of my YUI2 DataTable projects over to YUI3 (slowly...), and was trying to use the DataTable DataSource.Get JSON example. It took me awhile to figure out the trick to getting this to work.

The point is in the outgoing URI sent from DataSource it appends the callback function name that the JSON response needs to be wrapped in. At the present time, the callback function name is something like ..."YUI.Env.DataSource.callbacks.yui_xxxxxxxx". So for my Get query the full URI was ...
Code:
my_server_name.php?opt1=foo&opt2=bar&callback=YUI.Env.DataSource.callbacks.yui_3_3_0_1_1321477923083184
and my corresponding server JSON response needs to then be
Code:
YUI.Env.DataSource.callbacks.yui_3_3_0_1_1321477923083184( { ... your JSON here ... } );

After doing this, then the DataTable is populated properly as per the above Example. (A side remark; the User Guide example listed above is for a YQL query, where the callback wrapping is done automatically. For those of us neanderthals who still write our own backend servers it may be helpful to make this callback functionality more obvious! ;-)).

I took one of my simple YUI 3 DataTable IO examples and modified it to work with Get, the working example is at http://blunderalong.com/yui/dtb/dt_json_get_341.html if anybody is interested. This example is fully documented included with the server response and the PHP server listing.

There have been a few postings here lately referring to problems with DataSource.Get and DataTable and maybe this posting can help with that.

Good Luck!

Todd
  [ 1 post ]
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