Results 1 to 8 of 8

Thread: Tree: Add node sorted

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    Pilsen, Czech Republic
    Posts
    41
    Vote Rating
    0
      1  

    Post Tree: Add node sorted

    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.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    What framework and version?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    Pilsen, Czech Republic
    Posts
    41
    Vote Rating
    0
      0  

    Default

    Sorry, I forgot mention it.

    ExtJS 4.1.1.

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Quote Originally Posted by dherbolt View Post
    Sorry, I forgot mention it.

    ExtJS 4.1.1.
    Moved to Ext JS 4 forum
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #5
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    Pilsen, Czech Republic
    Posts
    41
    Vote Rating
    0
      -1  

    Default

    Quote Originally Posted by dherbolt View Post
    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.

  6. #6
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
      0  

    Default

    If all else fails, you always manually call the sort method of Ext.data.TreeStore, after adding your new node.

  7. #7
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    Pilsen, Czech Republic
    Posts
    41
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by friend View Post
    If all else fails, you always manually call the 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.

  8. #8
    Sencha Premium Member
    Join Date
    Aug 2007
    Location
    Pilsen, Czech Republic
    Posts
    41
    Vote Rating
    0
      0  

    Default

    Yes, it works, but only when I use:
    Code:
    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:
    Code:
    var store = Ext.getCmp('treepanel-1009').getStore();
    store.on('append', function () {this.sort(this.generateComparator())}, store);
    I get TypeError exception:
    Code:
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •