7

I'm trying to combine a draggable panel (on top), and a sortable panel (bottom).

Dragging works fine, but sorting fails.

Here is my JS fiddle: http://jsfiddle.net/dmUKY/9/

Both drag'n drop and sortable functions shares the droppable:drop function. When sorting elements, the function has to replace the selected object.

 drop: function (event, ui) {
    //alert($(this).parent().html());
    //alert($(ui.helper).attr('class'));
    var obj;
    if ($(ui.helper).hasClass('draggable')) {
        //alert('draggable');
      obj = $(ui.helper).clone();  
      obj.removeClass('draggable').addClass('editable')
      //obj.addClass('droppable');
      $(this).parent().append(obj);

    }


    //alert($(this).parent().html());
}

How should I combine these two functionalities?

2 Answers 2

19
$("#sortable").sortable({
    revert: true,
    stop: function(event, ui) {
        if(!ui.item.data('tag') && !ui.item.data('handle')) {
            ui.item.data('tag', true);
            ui.item.fadeTo(400, 0.1);
        }
    }
});
$("#draggable").draggable({
    connectToSortable: '#sortable',
    helper: 'clone',
    revert: 'invalid'
});
$("ul, li").disableSelection();

DEMO JSFIDDLE

I guess this is what you were looking for !!

Sign up to request clarification or add additional context in comments.

Comments

4

Change your code to this should do the trick:

obj.removeClass('draggable').addClass('editable').removeAttr('style');
//obj.addClass('droppable');
$(this).append(obj);

check on fiddle: http://jsfiddle.net/dmUKY/11/

2 Comments

thanks! How should I do if there is 2 separate sortable areas ? can I exchange items betwenn those ? JSfiddle: jsfiddle.net/dmUKY/11
ra_htial is the best :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.