JQuery UI Sortable Disable update function before receiving

I am using jquery ui to process a list, which you can sort and then also sort between another list. I use the update to sort inside, and it works great. When I sort, I just want to call the receive function, not the update. Currently, the update is called and then receives a call. Is there a way to skip the update call when sorting between lists?

<script> $ = jQuery $(function() { $( "#sortable1).sortable({ connectWith: ".connectedSortable", placeholder: "ui-state-highlight", update: function(event, ui) {processSortWithin(ui.item.attr("id"), ui.item.index()); }, receive: function(event, ui){ processSortBetween(ui.item.attr("id"), ui.item.index(),ui.sender.attr("id")); } }).disableSelection(); }); </script> 
+7
source share
3 answers

From: http://forum.jquery.com/topic/sortables-update-callback-and-connectwith

 update: function(e,ui) { if (this === ui.item.parent()[0]) { //your code here } } 
+12
source

I had a similar problem today, and the only solution I found was to introduce a flag variable that is set during the update event and checked during the stop event.

In your example, you are using a receive event that will fire on a list that receives a new item from some other list, so you should set it inside the $(".connectedSortable").sortable() .

Here is my way to distinguish between sorting (inside one list, processed in stop) or for moving (between two lists processed upon receipt):

 $(function() { position_updated = false; //helper flag for sortable below $(".sortable").sortable({ connectWith: ".sortable", update: function(event, ui) { position_updated = !ui.sender; //if no sender, set sortWithin flag to true }, stop: function(event, ui) { if (position_updated) { processSortWithin(ui.item.attr("id"), ui.item.index()); position_updated = false; } }, receive: function(event, ui) { processSortBetween(ui.item.attr("id"), ui.item.index(),ui.sender.attr("id")); } }).disableSelection(); }); function processSortWithin(id, position) { alert("sort within"); } function processSortBetween(id, position, sender_id) { alert("sort between"); } 

Working example: http://jsfiddle.net/myLff/2/

+4
source

Try the following:

 update: function(e,ui) { if (!ui.sender) { //your code here } } 
+3
source

All Articles