Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable dnd under a tree node if the node is expanded #509

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions extensions/DnD.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ define([
grid = this.grid,
store = grid.store;

var after = false;

if(!this.before && targetRow){
// target before next node if dropped within bottom half of this node
// (unless there's no node to target at all)
targetRow = targetRow.nextSibling;

var afterRow = targetRow;

for(targetRow = targetRow.nextSibling; !grid.row((targetRow)?targetRow:{}); targetRow=targetRow.nextSibling ) { }

if(!targetRow) {
targetRow = afterRow;
after = true;
}
}
targetRow = targetRow && grid.row(targetRow);

Expand All @@ -68,13 +78,13 @@ define([
// Delegate to onDropInternal or onDropExternal for rest of logic.
// These are passed the target item as an additional argument.
if(targetSource != sourceSource){
targetSource.onDropExternal(sourceSource, nodes, copy, target);
targetSource.onDropExternal(sourceSource, nodes, copy, target, after);
}else{
targetSource.onDropInternal(nodes, copy, target);
targetSource.onDropInternal(nodes, copy, target, after);
}
});
},
onDropInternal: function(nodes, copy, targetItem){
onDropInternal: function(nodes, copy, targetItem, after){
var store = this.grid.store,
targetSource = this,
grid = this.grid,
Expand All @@ -100,12 +110,13 @@ define([
// otherwise settle for put anyway.
// (put will relocate an existing item with the same id, i.e. move).
store[copy && store.copy ? "copy" : "put"](object, {
before: targetItem
before: (!after)?targetItem:null,
after : (after)?targetItem:null
});
});
});
},
onDropExternal: function(sourceSource, nodes, copy, targetItem){
onDropExternal: function(sourceSource, nodes, copy, targetItem, after){
// Note: this default implementation expects that two grids do not
// share the same store. There may be more ideal implementations in the
// case of two grids using the same store (perhaps differentiated by
Expand Down Expand Up @@ -135,7 +146,8 @@ define([
// since this coming from another dnd source, always behave as if
// it is a new store item if possible, rather than replacing existing.
store[store.copy ? "copy" : "put"](object, {
before: targetItem
before: (!after)?targetItem:null,
after : (after)?targetItem:null
});
});
});
Expand Down