EasyUI Forum
May 02, 2024, 12:45:48 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Drag and drop between tree and datagrid  (Read 7517 times)
CLKG
Guest
« on: October 28, 2015, 01:42:21 AM »

Is there any way that I can simply drag the grid's row onto a tree?
I can make the rows draggable:
Code:
onLoadSuccess: function (data) {
            var opts = $.data(this, 'datagrid').options;
            var trs = opts.finder.getTr(this, 0, 'allbody');
            trs.draggable({
                revert: true,
                proxy: 'clone'
            });
        }
But the tree(with dnd set to true) doesn't accept it……
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 29, 2015, 12:02:04 AM »

You must custom the datagrid proxy to make it draggable over the tree panel. The code below shows how to achieve this functionality.
Code:
$('#dg').datagrid({
onLoadSuccess: function(){
var opts = $(this).datagrid('options');
var trs = opts.finder.getTr(this, 0, 'allbody');
trs.draggable({
revert: true,
proxy: function(source){
var p = $('<div style="border:1px solid #ccc;"></div>');
p.html($(source).html()).appendTo('body');
return p;
}
})
}
})

You also need to custom the droppable tree to accept the dragging rows. This is a complex job. You must decide how to insert a new row to the tree, whether to delete the original row when dropped it successfully, etc.
Logged
CLKG
Guest
« Reply #2 on: November 01, 2015, 07:32:42 PM »

You must custom the datagrid proxy to make it draggable over the tree panel. The code below shows how to achieve this functionality.
You also need to custom the droppable tree to accept the dragging rows. This is a complex job. You must decide how to insert a new row to the tree, whether to delete the original row when dropped it successfully, etc.
Thank you! So the proxy must be appended to the body element.
But I donno how to custom the droppable tree like:
1 dnd = true cause that's exactly what I need.
2 When a grid's row dropped, don't do anything to the tree, and then change the row's category field and refresh the datagrid.
But it's hard for me, I donno how the tree's dnd works and what kind of element does the tree accepts.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: November 02, 2015, 12:00:02 AM »

The code below shows how to custom the droppable on tree nodes. Of course, you need to modify it to meet your requirement.
Code:
$('#dg').datagrid({
onLoadSuccess: function(){
var dg = $(this);
var opts = $(this).datagrid('options');
var trs = opts.finder.getTr(this, 0, 'allbody');
trs.draggable({
revert: true,
deltaX: 15,
deltaY: 15,
proxy: function(source){
var index = parseInt($(this).attr('datagrid-row-index'));
var title = dg.datagrid('getRows')[index]['itemid'];
var p = $('<div class="tree-node-proxy"></div>').appendTo('body');
p.html('<span class="tree-dnd-icon tree-dnd-no">&nbsp;</span>'+title);
return p;
}
})
}
});

$('#tt').tree({
onLoadSuccess: function(){
$(this).find('.tree-node').each(function(){
var opts = $(this).droppable('options');
opts.accept = '.tree-node,.datagrid-row';
var onDragEnter = opts.onDragEnter;
var onDragOver = opts.onDragOver;
var onDragLeave = opts.onDragLeave;
var onDrop = opts.onDrop;
opts.onDragEnter = function(e,source){
if ($(source).hasClass('tree-node')){
onDragEnter.call(this, e, source);
}
};
opts.onDragOver = function(e,source){
if ($(source).hasClass('tree-node')){
onDragOver.call(this, e, source);
} else {
allowDrop(source, true);
$(this).removeClass('tree-node-append tree-node-top tree-node-bottom');
$(this).addClass('tree-node-append');

}
};
opts.onDragLeave = function(e,source){
if ($(source).hasClass('tree-node')){
onDragLeave.call(this, e, source);
} else {
allowDrop(source, false);
$(this).removeClass('tree-node-append tree-node-top tree-node-bottom');
}
};
opts.onDrop = function(e,source){
if ($(source).hasClass('tree-node')){
onDrop.call(this, e, source);
} else {

}
};

function allowDrop(source, allowed){
var icon = $(source).draggable('proxy').find('span.tree-dnd-icon');
icon.removeClass('tree-dnd-yes tree-dnd-no').addClass(allowed ? 'tree-dnd-yes' : 'tree-dnd-no');
}
})
}
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!