javascript - jQuery UI Sortable and moving elements between lists -


i want grab items lists , drag them other blank lists.

this html structure:

<div class="structure">   <div id="row1" class="connected"></div>   <div id="row2" class="connected">     <div class="item">item 1</div>   </div>   <div id="row3" class="connected"></div>   <div id="row4" class="connected">     <div class="item">item 2a</div>     <div class="item">item 2b</div>     <div class="item">item 2c</div>   </div>   <div id="row5" class="connected"></div>   <div id="row6" class="connected">     <div class="item">item 3a</div>     <div class="item">item 3b</div>   </div>   <div id="row7" class="connected"></div> </div> 

there empty <ul> can put item in. after creates new empty <ul> before , after drag other items to.

this javascript

$( function() {   $(".structure div").sortable({     placeholder: "ui-state-highlight",     connectwith: ".connected",     items:       "> div",      receive:     function (event, ui) {        var targetrowid = $(this).attr("id");       var itemstargetrow = $("#"+ targetrowid +" .item").length;        if( itemstargetrow == 1 ) {         function uniqueid() {           return math.random().tostring(36).substr(2, 5);         };          $("#"+ targetrowid)           .before('<div id="row'+ uniqueid() +'" class="connected"></div>')           .after('<div id="row'+ uniqueid() +'" class="connected"></div>');       }     },      stop: function (event, ui) {        var fromrow = $(this).attr("id");       var isrowempty = $("#"+ fromrow +" .item").length;        if( isrowempty == 0 )       {         $("#"+ fromrow).next().remove();         $("#"+ fromrow).remove();       }     }   }).disableselection(); }); 

the problem:

when dropped item empty list, can't drag item anywhere else anymore.

any ideas?

ok here's problem

jquery starts page load , finds of areas 'connect' with. when add more divs jquery not realize there new areas allow drag , drop.

solution? need refresh jquery, somehting this:

var refresh = function(){    $( function() {   $(".structure div").sortable({     placeholder: "ui-state-highlight",     connectwith: ".connected",     items:       "> div",      receive:     function (event, ui) {        var targetrowid = $(this).attr("id");       var itemstargetrow = $("#"+ targetrowid +" .item").length;        if( itemstargetrow == 1 ) {         function uniqueid() {           return math.random().tostring(36).substr(2, 5);         };          $("#"+ targetrowid)           .before('<div id="row'+ uniqueid() +'" class="connected"></div>')           .after('<div id="row'+ uniqueid() +'" class="connected"></div>');          refresh();       }     },      stop: function (event, ui) {        var fromrow = $(this).attr("id");       var isrowempty = $("#"+ fromrow +" .item").length;        if( isrowempty == 0 )       {         $("#"+ fromrow).next().remove();         $("#"+ fromrow).remove();       }     }   }).disableselection(); });  } 

here's work in progress example: http://codepen.io/nilestanner/pen/grjjmj

you can @ answer more help: refresh list after adding item jquery ui sortable plugin


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -