PDA

View Full Version : how to reload nested list with TreeStore?



shatthi
24 Aug 2011, 8:05 PM
I have nestedlist with treestore. While loading first time the store is loaded perfectly and list is being displayed according to the store. When i click refresh button , my treestore should get reloaded with new data (with same data model as the first time) and nested list also need to be reloaded with new set of data.
Below is my treestore definition

rightPaneStoreData = getFolderListData();

rightPaneStore =newExt.data.TreeStore({

autoLoad:false,

model:'rightPaneModel',

root: rightPaneStoreData,
proxy:{

type:'memory',

reader:{

type:'tree',
root:'items'
}

},
listeners:{
datachanged:function(records){
alert("datachanged");
}
}

});

rightPaneStore.load();
In Ext.data.JsonStore i have accomplished the same using store.loaddata() method. But i couldnt find loaddata() method for TreeStore.
Kindly help me.

Eraser
14 Sep 2011, 1:41 AM
Hi shatthi,

have you already solved your problem? Could you share it if so?


Regards

shatthi
14 Sep 2011, 8:29 AM
No, still issue is open for me. If you get any solution , do share with me too

olear
18 Oct 2011, 10:56 AM
This works in my particular case. It won't refresh the whole store but it will refresh the path you took through the nested list.

refresh : function() {
var nList = Ext.getCmp('navlist'); // nested list
var listStore = nList.store;

var nodesToRefresh = nList.items.items; //each time you move down the tree this is where the nodes are held
for(var i =0 ; i < nodesToRefresh.length; i++) {
var recNode = nodesToRefresh[i].recordNode;
if(!recNode.ownerTree) {//for what ever reason the ownerTree is null for everything except the root
//sets the owner tree equal to its parent
recNode.ownerTree = nodesToRefresh[i-1].recordNode.ownerTree;
}
listStore.load({node:recNode}) // reload the node
}
},

larryweya
9 Jan 2012, 2:13 AM
In my case, I needed to go back to the root node after re-loading the nested list so I overode the NestedList.setActivePath function to this


setActivePath: function(path) { // a forward leading slash indicates to go
// to root, otherwise its relative to current
// position
var gotoRoot = path.substr(0, 1) === "/",
j = 0,
ds = this.store,
tree = ds.tree,
node, card, lastCard,
pathArr, pathLn;


if (gotoRoot) {
path = path.substr(1);
}


pathArr = Ext.toArray(path.split('/'));
pathLn = pathArr.length;




if (gotoRoot) {
// clear all but first item
var items = this.items,
itemsArray = this.items.items,
i = items.length;


for (; i > 0; i--) {
this.remove(itemsArray[i - 1], true);
}


// verify last item left matches first item in pathArr
// <debug>
/*var rootNode = itemsArray[0].recordNode;
if (rootNode.id !== pathArr[0]) {
throw new Error("rootNode doesn't match!");
}*/
// </debug>


// we've removed all cards, set this back to 0
j = 0;
}




// loop through the path and add cards
for (; j < pathLn; j++) {
if (pathArr[j] !== "") {
node = tree.getNodeById(pathArr[j]);


// currently adding cards and not verifying
// that they are true child nodes of the current parent
// this would be some good debug tags.
card = this.addNextCard(node);


// leaf nodes may or may not have a card
// therefore we need a temp var (lastCard)
if (card) {
lastCard = card;
}
}
}


// <debug>
if (!lastCard) {
throw new Error("Card was not found when trying to add to NestedList.");
}
// </debug>


this.setActiveItem(lastCard, false);
this.fireEvent('listchange', this, lastCard);
this.syncToolbar();
}

Then I called it like this nestedList.setActivePath("/root")

orenr
2 Feb 2012, 5:58 AM
olear your answer just helped me a lot! thanks!