javascript - How to drag one or more items to an element using both Draggable and Selectable JQuery -
i'd know how drag 1 or more items (individual person records in case, via avatar photo) target (in case list of cities) , update database dragged items details of item dragged to.
i have working single items @ moment.
i have sidebar list of locations retrieve database entityframework:
<ul> <li class="droppable"> <span>sydney</span> </li> <li class="droppable"> <span>brisbane</span> </li> <li class="droppable"> <span>melbourne</span> </li> </ul>
in main window have grid of people's images , i'm using jquery ui selectable enable these selected:
<ul class="people-list" id="selectable"> @foreach (var item in model.people) { <li> <img src="@item.photo" style="width:100%" class="img-polaroid" /> </li> } </ul> $(function () { $("#selectable").selectable({ selected: function (event, ui) { if ($(ui.selected).hasclass('click-selected')) { $(ui.selected).removeclass('ui-selected click-selected'); } else { $(ui.selected).addclass('click-selected'); } }, unselected: function (event, ui) { $(ui.unselected).removeclass('click-selected'); } }); });
what i'd do, once user has selected 1 or more people, them able drag selected people 1 of locations, , update database.
so if user drags personid 4,5 , 9, 'sydney' need update database asyncronously perform this.
i've added jquery draggable , droppable , can drag individual people 1 of locations, , update database, can't work selectable allow multiple items selected.
$(function () { $(".img-polaroid").draggable({ containment: "document", helper: 'clone', opacity: 0.70, zindex: 10000, }); $(".droppable").droppable({ hoverclass: "ui-state-hover", tolerance: "pointer", drop: function (event, ui) { $.ajax({ type: "post", url: '/person/updatelocations/' + $(this).attr("id") + '|' + $(ui.draggable).attr("id"), success: function (data) { $('.draggable').draggable('destroy'); $('#successmsg').empty(); $('#successmsg').append(data); $('#successdiv').show(); $('.draggable').draggable({ revert: true }); } }); } }); });
i find out .selectable() , .draggable() not working on same element. suggestion create own multi-select behaviour.
embedding value (id) html elements
embed ids, value, html elements accordingly both cities , persons, eq : <li class="droppable" data-val="sydney"><span>sydney</span> </li>
, <img src="" class="img-polaroid" data-val="4"/>
.
imitating multi-select
every selected element tagged specific class, defined in selectedclass = "ui-selected"
. class toggled click event. element may not selected on drag event, therefore need add selectedclass
on draggable.start
.
drag
.draggable
works on single dragged element (cmiiw), move selected element changing top
, left
properties of elements. set position=relative
of #selectable
element.
drop
actions need done on droppable.drop
callback : prepare data , perform ajax request. if ajax request succeed selectable elements removed , update message. if ajax request failed selectable elements going placed on original position.
please take on example : http://jsfiddle.net/marson/zscab/131/. hope helps.
Comments
Post a Comment