jquery - How to manually trigger 'update' in ui-sortable -
i'm using ui sortable in each item delete
button. here delete function:
$('.delete_item').click(function(){ $(this).closest('.grid_3_b').remove(); initsortable(); $(".sortable").sortable('refresh').trigger('update'); });
the div
get's removed want to, there no update
data sent php.. script won't save order , deleted item..
here initsortable();
function:
function initsortable() { $( ".sortable" ).sortable({ items: '.grid_3_b, .dropable', connectwith: ".sortable", placeholder: "placeholder", remove: function(event, ui) { if(!$('div', this).length) { $(this).next('.dropable').remove(); $(this).remove(); } initmenu(); }, receive: function(event, ui) { if( $(this).hasclass( "dropable" ) ) { if( $(this).hasclass( "gallery__item--active" ) ) { $(this).before( "<div class=\"dropable gallery__item sortable\"></div>" ); $(this).after( "<div class=\"dropable gallery__item sortable\"></div>" ); initsortable(); $(".sortable").sortable('refresh').trigger('update'); initmenu(); } } }, update : function () { var neworder = new array(); $('.sortable').each(function() { var id = $(this).attr("id"); var pusharray = new array(); $('#' + id).children('div').each(function () { var art = $(this).attr("data-art"); var pos = $(this).attr("data-pos"); pusharray.push( {data:{'art':art, 'pos':pos}} ); }); neworder.push({'id':id, 'articles':pusharray}); }); $.post("example.php",{'neworder': neworder},function(data){}); initmenu(); } }).disableselection(); } initsortable();
also, remove
function deletes column when it's empty, doesn't work when deleted latest item in column.. because update trigger isn't called?
for manually triggering events in jquery-ui sortable, instead of specifying handler in options object, need bind event handler after sortable initialization.
for example following not work
$('ul').sortable({ update: function () { console.log('update called'); } }); $('ul').trigger('sortupdate'); // doesn't work
following works
$('ul').sortable(); $('ul').on('sortupdate',function(){ console.log('update called'); }); $('ul').trigger('sortupdate'); // logs update called.
Comments
Post a Comment