Spry datasets before loading and when reloading

Posted on 2008-11-19
Medium Priority
Last Modified: 2013-11-11

I have multiple spry datasets on a page. Is there any way I could get the spry framework to wait until all the data sets were ready and then do something (in this case it would be remove the display:none attribute from a div).

Also, is it possible to have the spry framework check if a certain element exists in the xml data set and do something if it doesn't everytime the data is reloaded (I have it set to reload every 10 seconds).

I have looked through the documentation but can't find anything covering these two areas so if anyone can point me in the right direction or pop me some sample code I'd be greatful.

Thanks a lot,

Question by:intechfs
  • 4
  • 3
LVL 70

Expert Comment

by:Jason C. Levine
ID: 22998142
Hi intechfs,

What you can do is add a loading state region to the spry regions:

<div spry:state="loading" align="center">Please wait...data is loading now</div>

Place the above code inside of the Spry region container.  The state:"loading" parameter tells Spry to display the contents of this div while the data is being generated.

Author Comment

ID: 23002405
Yes but that only works on a per data set basis. I want a global option that would be on the entire page and would be displayed whilst all the data sets loaded and when they had all loaded then the page content is shown.
LVL 70

Expert Comment

by:Jason C. Levine
ID: 23006444
I don't think that's possible.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

intechfs earned 0 total points
ID: 23050166
I worked out a way of doing it.

For anyone else interested you need to add observers to the data sets like this:
var dsf = new Spry.Data.XMLDataSet( "../../test_data/favs.xml", "favs/fav", { useCache: false } );
dsf.setColumnType("@id", "number");
dsf.addObserver ( testDSF );

Then I wrote some custom functions for each observer which set a flag to 1 when the set is loaded and then runs another function which tests to see if all the flags for all sets are at 1 and if they are it shows the page.

Like this:
function testDSF (notificationType, dataSet, data) {

      //check to see if the data has just been loaded
      if ( notificationType == "onPostLoad" ) {

            //if this is the first time this data set has been loaded
            if ( dsfLoad == 0 ) {
                  dsfLoad = 1;

      //if spry is reporting a data load error
      } else if (notificationType == "onLoadError") {
            window.location = "../../error?r=df";

//little function to test if all data sets have been loaded for the first time, and if they have then we can display the page and remove the loading animation
function allLoad () {

      //if all the data sets are loaded then we can do stuff!
      if ( ( dsvLoad == 1 ) && ( dsfLoad == 1 ) ) {
            document.getElementById('doneLoad').style.display = '';
            document.getElementById('preLoad').style.display = 'none';

LVL 70

Expert Comment

by:Jason C. Levine
ID: 23052796
Right, but you needed a custom function to handle it.  Spry alone does not support it...

Great work, though!

Author Comment

ID: 23056769
Yes true.. there are quite a lot of things Spry can do, but there quite poorly documented.

Adding observers for example, which only has very limited explanation.
LVL 70

Expert Comment

by:Jason C. Levine
ID: 23057770
>> but there quite poorly documented.

One gets the feeling that the whole Spry project was started late and rushed to the table before it was really complete.  1.4 was awful and buggy and there was zero documentation.  1.6.1 is better, but the documentation is largely in the form of the examples at the Adobe labs.  

You should send the above to them...

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question