PDA

View Full Version : [SOLVED] Best practice for handling AJAX calls in widget



dotnetCarpenter
3 Oct 2007, 8:24 AM
Hi all!

I'm developing a widget (for now I call it Ext.ux.Calendar) and was wondering how to handle AJAX calls. First a little bit of info about my component.

My component has a store object which can be any of the EXT data stores. It builds the calendar by using Ext.MasterTemplate and it has an eventhandler that builds each day of the calendar (the user can set the timespan the calendar will show). After the initial config settings, like on what element to render in, what data store to use ect. You just call my component .render() method.

My initial idea was to load the data on render and then start building the (X)HTML but then it dawn on me that I couldn't be sure that the data was loaded when I got to building the days.
Should I first query the data and then build the (X)HTML or is that considered inefficient?

Regards, Jon.

PS. I hope my description is not too vague. :s

DigitalSkyline
3 Oct 2007, 2:31 PM
Seems like you would build the shell, request the data (json/xml), and on return build the html -- How else could it be done?

I suppose if you built the month out, you could later fill in events after they are retrieved... you'd have to keep track of all those divs though.

dotnetCarpenter
4 Oct 2007, 9:52 AM
I could build the HTML for the months first when the component initialize but then it would have to be an public method, so that I can invoke it again when the timespan change, which would be bad, because it doesn't make sense for the developer to use it... unless I make it a private method but I don't know how to do that unless the class is a singleton, which I don't want. Hmm.. I have to experiment a bit :s

dotnetCarpenter
4 Oct 2007, 10:52 AM
Iunless I make it a private method but I don't know how to do that unless the class is a singleton, which I don't want. Now I do, so that's the route I'm gonna take =D>