Drag-and-drop made easy
Dragging and dropping nodes within trees is easy with Ext JS 4. To allow the drag-and-drop action within a tree, we need to add the TreeViewDragDrop
plugin as follows:
Ext.define('TTT.view.admin.CompanyTree', { extend: 'Ext.tree.Panel', xtype: 'companytree', title: 'Company -> Projects -> Tasks', requires: ['TTT.store.CompanyTree','Ext.tree.plugin.TreeViewDragDrop'], store: 'CompanyTree', lines: true, rootVisible: false, hideHeaders: true, viewConfig: { preserveScrollOnRefresh: true, plugins: { ptype: 'treeviewdragdrop' } }, etc
This simple inclusion will enable the drag-and-drop support for your tree. You will now be able to drag-and-drop any node to a new parent. Unfortunately, this is not exactly what we need. A task node should only be allowed to drop on a project node, while a project node should only be allowed to drop on a company node. How can we restrict the drag-and-drop action...