O'Reilly logo

Ext JS 4 Web Application Development Cookbook by Stuart Ashworth, Andrew Duncan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dragging-and-dropping nodes within a tree

Dragging-and-dropping nodes within a tree or between trees can help make your application more interactive for your users. Ext JS has built-in drag-and-drop nodes making it easy for developers to add this functionality. Here, we will learn how to drag nodes from one tree to another.

How to do it...

  1. Create a store and define some dummy inline data for the first tree:
    var storeForTreeA = Ext.create('Ext.data.TreeStore', {
        root: {
            expanded: true,
            children: [{
                text: "Item 1",
                leaf: true
            },{
                text: "Item 2",
                leaf: true
            },{
                text: "Item 3",
                leaf: true
            },{
                text: "Item 4",
                leaf: true
            }]
        }
    });
  2. Create a tree and add the Ext.tree.plugin.TreeViewDragDrop plugin:
    var treeA = Ext.create('Ext.tree.Panel', { title: 'Tree One ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required