Refeshing an ItemFileReadStore
by Gary Acord

This is a pretty common need with a pretty simple solution.  How do you clear out the existing Data in a store, and populate it with new Data in Dojo 1.2?

The solution is pretty easy. Let’s assume you have an ItemFileReadStore (this works with ItemFileWriteStore as well) named myStore.

<div dojoType="dojo.data.ItemFileReadStore" url="myData.json" id="myStore" jsid="myStore" clearOnClose="true"></div>

This creates an ItemFileRead store and assigns it to the global variable myStore.

Then you can force it to reload as such:

myStore.close();
myStore.fetch();

If you need to change the url of the store (as of Dojo 1.2.3) you can do it like this:

myStore.close();
myStore._jsonFileUrl = newurl;
myStore.fetch();

… and if you have a grid bound to the store, force it to reload

myStore.close();
myStore.fetch();
myGrid._refresh();

And that’s all there is to it.  Happy Dojoing!

This entry was posted on Saturday, January 31st, 2009 at 10:53 pm and is filed under Dojo Cookies. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Refeshing an ItemFileReadStore”

  1. bngsudheer Says:

    This is cool. I was looking at queryReadStore to achieve this functionality with autocomplete fields. Happy to know I don’t have to for small lists.

  2. dcremo Says:

    Hello. I’m trying to do the same thing with a dijit.Tree bound to a ForestStoreModel bound to ItemFileWriteStore from a JSON Url, but I cannot see the updated data.
    Looking to the 1.2.3 (and even in 1.3.1) sources I can’t see any tree._refresh() or similar function. Any help is much appreciated.

  3. viro Says:

    Using Dojo 1.3.1, I’m using this method to refresh a store bound to a grid. The new url points to a php scripts that queries data. All of this works fine but for a small yet annoying glitch :

    The grid size ( height ) grows everytime I try to reload the store. It grows with blank space, not new content ( the php script returns only one line to be displayed in the grid anyways)

    The store does have the clearonclose flag set to true, if that’s of any importance.

    Here are the store and grid :

    and here is the function to reload :

    function majTable(param)
    {
    jsonStore.close();
    jsonStore._jsonFileUrl = “ventes.php?”+param;
    jsonStore.fetch();
    myGrid._refresh();
    }

    Any help is much appreciated !

Leave a Reply

You must be logged in to post a comment.