Search code examples
extjsdrag-and-dropextjs4.2treepanel

Extjs: drag n drop tree node and its children to a grid


How can I drag and drop a node(parent) and all its children without selecting them, when the parent node is selected and dragged in the tree?

Sample code which I have tried


Solution

  • In the beforedrop event, you need to add the child nodes to the data.records array. Every record in that array will be included in the drag & drop process. Likewise, if you did not want to include a node that was dragged and dropped, you would remove that record from data.records while in the beforedrop event.

    Please take a look at my sample code to see an approach for how to add the child nodes.

    The relevant piece is:

    var childNodes = Ext.Array.from(record.childNodes) || []; // ensure it's an array
    
    for (var i=0; i < childNodes.length; i++) {
        data.records.push(childNodes[i]);
    }