- The Book of Dojo
- Quick Installation
- Hello World
- Debugging Tutorial
- Introduction
- Part 1: Life With Dojo
- Part 2: Dijit
- Part 3: JavaScript With Dojo and Dijit
- Part 4: Testing, Tuning and Debugging
- Part 5: DojoX
- The Dojo Book, 0.4
Using Datastores
Submitted by leesakcp on Tue, 07/10/2007 - 21:59.
This section contains documentation on the operations that are most common to data access: Searching, Sorting, Pagination, and Lazy Loading.
- Printer-friendly version
- Login or register to post comments
- Subscribe post

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