Login Register

Using Datastores

This section contains documentation on the operations that are most common to data access:  Searching, Sorting, Pagination, and Lazy Loading.

How to change data store dynamiclly ?

Hi,

Say I have a combo drop down which is pointing to a predefined data store. After the page is loaded. if I want to switch the drop down to a new data store, as it often happens in Ajax, a way to do this ?

Thanks.

Function to do that

I use a very similar function to change ANY dataStore from my aplication (I mean, u can put conditions to also change dataStore of grids for exemple).


/*
* Function to change dataStore from filtering
*
* Param:
* myObj - ID of the filtering
* myURL - Your JSON return URL (U might use GET to recive for exemplo php....
*/

function ChangeList(myObj,myURL) {
/*
Disable the menu and put a wait message
*/
dijit.byId(myObj).setDisplayedValue("Loading...");
dijit.byId(myObj).setDisabled(true);

/*
Create new dataStore with the gived URL
*/
var vstore = new dojo.data.ItemFileReadStore({url: myURL });

/*
Set the new store in the dijit "SELECT"
*/
dijit.byId(myObj).store = vstore;

/*
Fetch the values
Remember query{ name: "*" }.... where "name" refer to one of the fields...
*/
var newValue = vstore.fetch(
{
query: {name: "*"} ,
onComplete: function(items, request) {
dijit.byId(myObj).setValue(items[0].value);
dijit.byId(myObj).setDisplayedValue(items[0].name);
}
});
/*
Enable the dijit "SELECT"
*/
dijit.byId(myObj).setDisabled(false);

} // END