Showing posts with label reload store. Show all posts
Showing posts with label reload store. Show all posts

Monday, June 27, 2011

Extjs Store FAQs

While using Extjs store you will come across some common questions like how to reload a store or change its url etc.

Below is the listing of some of the extjs store FAQs and their answers.

Change store url dynamically :
store.proxy.url = newUrl;

Update or add store baseparams
store.baseParams = {
    sort : "name",
    selectedUser : store.getById(userId).data.userName
}
or
store.baseParams.selectedUser :  store.getById("10").data.userName;

Load store from another store
store2.loadData(store1.reader.xmlData);
//to load store with json data use store1.reader.jsonData

Reload the store :
 store.reload(store.lastOptions);

Load store with the value stored in local (javascript) variable :
store.loadData(localVariable); 
// localVariable contains the data to be loaded into the store.

Append data to existing store :
store.loadData(newData, true) //newData contains the data to be appended

Iterate over store records :
store.each(function(currentRecord) {
    alert(currentRecord.id); 
    // alerts record id for each store record
});

Remove a record from the store :
store.remove(recordToRemove);
//recordToRemove is the record object to be removed from store.
//This can also be an array if you want to remove multiple records.
//Use store.removeAll() to remove all the records
//If you know index of the record then use store.removeAt(recordIndex)