Results 1 to 8 of 8

Thread: Removing Multiple Selected Nodes

  1. #1

    Default Removing Multiple Selected Nodes

    I'm using a TreePanel with Ext.tree.MultiSelectionModel. My tree has a hidden root node and all the children nodes are leafs. I would like my users to be able to select multple nodes and remove them. It iterates over the selected nodes calling remove on them. I've also tried this code using removeChild() on the root node. The problem is, after removing the selected nodes, all references in the array returned from getSelectedNodes() seem to be invalid and Firebug returns an error. The code I'm using is below.

    Code:
    Ext.each(this.getSelectionModel().getSelectedNodes(), function(node) {
      node.remove()
    });
    All I want to know is how to remove multiple nodes using the Ext.tree.MultiSelectionModel.

  2. #2
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,488

    Default

    After removing the nodes call clearSelections on the selection model.
    Aaron Conran
    @aconran

  3. #3

    Default Updated Remove Function

    I updated the function I was calling and now it works. However, I'm not convinced this is the proper or most effecient way to perform this action. The update code is below:

    Code:
    var nodes;
    
    while ((nodes = this.getSelectionModel().getSelectedNodes()).length > 0) {
      nodes[0].remove();
    }

  4. #4

    Default

    Quote Originally Posted by aconran View Post
    After removing the nodes call clearSelections on the selection model.
    I can't get to the point of removing all the nodes because it fails after removing the first node. I don't want to clearSelections because I have yet to remove the remaining selected nodes.
    Last edited by johnmckinzie; 28 Apr 2008 at 11:13 AM. Reason: typo

  5. #5
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,488

    Default

    Try this:
    Code:
    var sm = Ext.getCmp('tree').getSelectionModel()
    var sels = sm.getSelectedNodes();
    sm.clearSelections();
    for (var i = 0; i < sels.length; i++) {
    	sels[i].remove();
    }
    Aaron Conran
    @aconran

  6. #6

    Default

    Thanks for the solution. I tried it and it works fine. I guess you need to unselect the nodes before removing.

  7. #7
    Ext User
    Join Date
    Mar 2008
    Location
    Philadelphia, PA, USA
    Posts
    97

    Default

    @Ext Team: Is there a particular reason why you have to deselect the nodes before removing them? I'm just curious to know if something strange to going on under the hood with selecting/deselecting.
    Marc Weil
    Software Engineer
    Oracle Primavera GBU

    Any and all code samples that are authored by me and posted on the Sencha forums or website are hereby released into the public domain and I release anyone or entity of liability by using said code samples unless explicitly stated otherwise.

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    Deleting deselects the record (Obviously) which changes the internal Array of selected Records.

    So you have to capture the Array first, and then process it.

Posting Permissions

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