Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflict between Drag and drop and sortable jquery plugins

I have a conflict when trying to mix those plugins, i have based my script in some demos. The problem is that when i drag something inside the same list it triggers the drop event and that item is added to the end of the list, wich is correct if the item is dropped in another list, but not in the same, when i drop it in the same list i want to insert it in that position (it works if i disable the drop event)

js code:

$(document).ready(function() {
      $("#sortlist1").treeview();
      $("#sortlist1").droppable({  
        accept: ".item",  
        drop: function(ev, ui) {
            alert(ui.sender)
            $("#sortlist1").append($(ui.draggable));     
        } 
      });  
      $("#sortlist2").droppable({  
            accept: ".item",
            drop: function(ev, ui) {
                $("#sortlist2").append($(ui.draggable));  
            }  
          });
      $("#sortlist3").droppable({  
            accept: ".item",  
            drop: function(ev, ui) {
                $("#sortlist3").append($(ui.draggable));  
            }  
          });
      $('.sortlist').sortable({
          handle : '.icono',
          update : function () {
              $('input#sortlist').val($('.sortlist').sortable('serialize'));
          }
        });
    });

And html:

<ul class="sortlist treeview lista" id="sortlist1">
        <li id="listItem_1" class="expandable closed item">
            <div class="hitarea closed-hitarea expandable-hitarea lastExpandable-hitarea">
                <img src="img/arrow_out.png" class="icono" alt="move" />
            </div>
            numero 1<input type="checkbox" />
            <ul class="sortlist" id="sublist">
                <li id="sublistItem_1"><img src="img/arrow_out.png" class="icono" alt="move" />numero 1<input type="checkbox" /></li>
                <li id="sublistItem_2"><img src="img/arrow_out.png" class="icono" alt="move" />numero 2<input type="checkbox" /></li>
            </ul>
        </li>
        <li id="listItem_2" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 2<input type="checkbox" /></li>
        <li id="listItem_3" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 3<input type="checkbox" /></li>
        <li id="listItem_4" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 4<input type="checkbox" /></li>
        <li id="listItem_5" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 5<input type="checkbox" /></li>
        <li id="listItem_6" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 6<input type="checkbox" /></li>
        <li id="listItem_7" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 7<input type="checkbox" /></li>
        <li id="listItem_8" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 8<input type="checkbox" /></li>
        <li id="listItem_9" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 9<input type="checkbox" /></li>
        <li id="listItem_10" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 10<input type="checkbox" /></li>
        <li id="listItem_11" class="item"><img src="img/arrow_out.png" class="icono" alt="move" />numero 11<input type="checkbox" /></li>
  </ul>
  <ul class="sortlist treeview lista" id="sortlist2">
  </ul>
  <ul class="sortlist treeview lista" id="sortlist3">
  </ul>
like image 837
Juan Techera Avatar asked Dec 17 '08 18:12

Juan Techera


2 Answers

You cannot mix those plugins: they process the same events, and cannot cooperate together. Either rethink your UI, or use different tools.

Is it possible to do it? Yes, of course. For example, Dojo DnD allows both sorting and drag-and-drop using just one component: test_dnd.html (link to the debugging server).

like image 77
Eugene Lazutkin Avatar answered Oct 30 '22 12:10

Eugene Lazutkin


You can do this, sort of.

Create two links in each item to use as handles.

Make the list sortable by one handle.

Make the list draggable by the other handle.

Now, when you grab one handle or the other, only one plugin will be activated, and events will be processed correctly.

like image 29
Eli Avatar answered Oct 30 '22 12:10

Eli