Topic: Tree: sort after drag

Hello, first of all: the plugin is awesome, really like it alot.

My question: how to use sorting in combination with drag and drop.

tried something like this:

onComplete: function(){
    this.current.getParent().sort();
}

Please help !
Thx

Re: Tree: sort after drag

yes this don't work, sort really don't sort nodes :-). It used internally with sortable tree, when all nodes sorted.

You can try this:

Mif.Tree.Node.implement({
    
    redraw: function() {
        this.$draw = false;
        this.tree.$getIndex();
        this.getDOM('children').innerHTML = '';
        Mif.Tree.Draw.update(this);
        return this;
    }       

});


this.current.getParent().sort(function(node1, node2){
    if(node1.name > node2.name){
        return 1;
    }else if(node1.name < node2.name){
        return -1;
    }else{
        return 0;
    }
});
this.current.getParent().redraw();

and onDrop event or it'll use old parent

Re: Tree: sort after drag

Thx for the respone!

Will try this out tomorrow,
now i need to sleep smile

Re: Tree: sort after drag

it don't work if sorted childrens have subchildrens, you can try this:

var parent = this.current.getParent();
parent.sort(function(node1, node2){
    if(node1.name>node2.name){
        return 1;
    }else if(node1.name<node2.name){
        return -1;
    }else{
        return 0;
    }
});
var childrenEl = parent.getDOM('children');
for(var i = 0, l = parent.children.length; i < l; i++){
    parent.children[i].getDOM('node').inject(childrenEl);
    Mif.Tree.Draw.update(parent.children[i]);
}
parent.tree.$getIndex();
this.current.tree.scrollTo(this.current);

for tree (not forest)

Re: Tree: sort after drag

Absolutely awesome!, thx man big_smile
should make this a feature wink

I have another question:
Sometimes i want to cancel a drag action.

I should explain my situation:
Nodes in the tree represent site content,
when a node is selected the content of that node will be displayed in a form.
So when the user edits the form and clicks on another node i display a overlay
with a message like "There are unsaved changes, save YES / NO".

The overlay will show on mousedown (the select event).
And if the user keeps the mouse button down and moves the mouse he will drag the node
behind the overlay.

So my question is:
Is it possible to cancel the current drag action ?

Tried this:

onDrag: function(){
    if(dragIsDisabled)
    {
        this.where = 'notAllowed';
        this.emptydrop();
        return;
    }
}

Last edited by mrgroovy (2010-07-01 01:44:02)

Re: Tree: sort after drag

to disable node drag set node.dragDisabled = true

Re: Tree: sort after drag

Thx for your help,
I really appreciate it smile

Re: Tree: sort after drag

first I'd like to say thanks you for all the contributions in this pose - helps me alot

though just one extra thing to moro's solution

if sorting from tree.root (with foreset), I needed to change following line

var childrenEl = parent.getDOM('children');

to this

if (parent == self.tree.root){
    var childrenEl = self.tree.container.getElement('.mif-tree-children-root')
}
else{
    var childrenEl = parent.getDOM('children');
}

otherwise miftree will complain when you try to call getDOM()

Last edited by muskmelon (2012-03-19 10:04:50)