views:

162

answers:

1

Hi,

I'm trying to use the sortable widget for my site. I have a mini scheduling app that I'd like to display a list of appointments for the week sorted by days.

For this example we'll use only two days ( 2 lists ). If I wanted to drag an appointment (list item) from day 2 over to day 1, is there a way I can callback the id of list 1 after I dragged an item to it? I can find the id of the parent list upon page load but I can't seem to be able to pull the new id after sort. Is this even possible?

<script type="text/javascript"> $(function() { $("#day1, #day2").sortable({ connectWith: '.sortable' }).disableSelection(); }); </script>

====

Ok here's what I have so far but i can't seem to get the items being dragged to stick to the list their being dragges to:

<script type="text/javascript">
$(document).ready(function() {
        $("#sortable1, #sortable2").sortable().disableSelection();
        $("ul:first h3").droppable({
            accept: ".connectedSortable li",
            hoverClass: "ui-state-hover",
            drop: function(ev, ui) {
                var $item = $(this);
                var $list = $($item.find('a').attr('href')).find('.connectedSortable');
                $(this).appendTo($list);
        }
    });
});

</script>
A: 

Look at the following callback on the following page - it may help...

 drop: function(ev, ui) {
    var $dropped_on_item = $(this);
}

http://jqueryui.com/demos/sortable/#connect-lists-through-tabs

This would mean making your target lists 'droppable' as well as 'sortable' though.

calumbrodie
Ok this is going to sound like a stupid question but I'm stuck; so I can replace sortable with droppable without having tabs? I need to have all lists visible at once to compare, I just can't see if droppable has a requirement of tabs.
PARyGuy
no - all lists that you want to be able to drag/drop to/from must be 'sortable' - on top of that make the list that you want to drop onto 'droppable'. It may have this applied automatically already by jquery UI but I'm not sure - you'll need to see if you can use the drop method ) example above, in each circumstance.
calumbrodie
I am taking the easy way out and going with this :)http://github.com/robmonie/jquery-week-calendar/downloadsI appreciate your help
PARyGuy
Well this is the final working code - as I expected you can make each list 'droppable' which gives you a 'drop' callback to use when items are dropped on the list.... see here (for the learning)..http://jsbin.com/avidu3 and here for the code... http://jsbin.com/avidu3/editthen mark this question as answered or flag it to be closed
calumbrodie