PDA

View Full Version : Tree: Add node sorted



dherbolt
30 Jul 2012, 4:22 AM
Hi all,
Is there any way how to add node into tree with applied sort? I have defined Ext.data.TreeStore with sorter, but it is applied only when data are loaded.
If I add node into tree by parentNode.appendChild(node), the node is added as last child of parent (I know, it's append). But how I can add node according to current sort state?
I'm looking for something like Ext.data.Store.addSorted.

Thanx for advice.

mitchellsimoens
30 Jul 2012, 8:13 AM
What framework and version?

dherbolt
30 Jul 2012, 11:47 AM
Sorry, I forgot mention it.

ExtJS 4.1.1.

mitchellsimoens
30 Jul 2012, 11:52 AM
Sorry, I forgot mention it.

ExtJS 4.1.1.

Moved to Ext JS 4 forum

dherbolt
31 Jul 2012, 1:20 AM
Hi all,
Is there any way how to add node into tree with applied sort? I have defined Ext.data.TreeStore with sorter, but it is applied only when data are loaded.
If I add node into tree by parentNode.appendChild(node), the node is added as last child of parent (I know, it's append). But how I can add node according to current sort state?
I'm looking for something like Ext.data.Store.addSorted.

Thanks for advice.

In ExtJS 3, TreeNode.appendChild adds new node to proper position according to current sort state if Ext.tree.TreeSorter is defined for the Tree.

friend
31 Jul 2012, 4:14 AM
If all else fails, you always manually call the sort (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.data.TreeStore-method-sort) method of Ext.data.TreeStore, after adding your new node.

dherbolt
31 Jul 2012, 6:00 AM
If all else fails, you always manually call the sort (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.data.TreeStore-method-sort) method of Ext.data.TreeStore, after adding your new node.

Yes, I know. But I don't want to sort whole store I added only one node. It is enough to sort only items of parent node.

dherbolt
1 Aug 2012, 12:23 AM
Yes, it works, but only when I use:


Ext.getCmp('treepanel-1009').getRootNode().appendChild({text: '0a'});
Ext.getCmp('treepanel-1009').getStore().sort(this.generateComparator());

It is "user unfrendly" because I have to call sort manually after append.

If I use store's "append" event:


var store = Ext.getCmp('treepanel-1009').getStore();
store.on('append', function () {this.sort(this.generateComparator())}, store);


I get TypeError exception:


TypeError: sibling is undefined
http://localhost/extjs_4.1.1/ext-all-dev.js
Line 77912


Tested on xml tree example from ExtJS 4.1.1 package.