PDA

View Full Version : treeviewdragdrop - allow only drag & drop within the same parent



ttngo
12 Apr 2015, 8:27 AM
Is there a way to allow only dragging and dropping within the same parent? That is, not allowing a node to be dragged to a different parent. I am looking at the beforedrop listener, hoping that I can compare the the current parent against the targeted parent. However, upon inspection of the parameters wihin beforedrop, I don't see how I can get the old parent.

Any hints is much appreciated.

yeghikyan
13 Apr 2015, 3:57 PM
Ext.application({
name: 'Fiddle',


launch: function() {
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "detention",
leaf: true
}, {
text: "homework",
expanded: true,
children: [{
text: "book report",
expanded: true,
children: [{
text: "book report",
leaf: true
}, {
text: "algebra",
leaf: true
}]
}, {
text: "algebra",
leaf: true
}]
}, {
text: "buy lottery tickets",
leaf: true
}]
}
});


Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 300,
store: store,
rootVisible: false,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop'
},
listeners: {
beforedrop: function(node, data, overModel, dropPosition, dropHandlers) {
data.records.forEach(function(record) {
//From path you can get the parentId
console.log(record.getPath('text'));
})
}
}
},
renderTo: Ext.getBody()
});
}
});