Question

I am using this nested sortable plugin http://mjsarfatti.com/sandbox/nestedSortable/ to sort image slideshow from my content management system.

I tried using html5 ondrop event so that whenever a drop event occurs the sort will be saved through ajax post but still on drop does not go to save_order function

HTML:

<div ondrop="save_order(event)" ondragover="return false;>
    <ol class="sortable">
        <li id="list_1" draggable="true" class="mjs-nestedSortable-no-nesting"><div><img src="{image_path}"/></div></li>
        <li id="list_2" draggable="true" class="mjs-nestedSortable-no-nesting"><div><img src="{image_path}"/></div></li>
    </ol>
</div>

JS:

$(document).ready(function(){
    $('.sortable').nestedSortable({
        disableNesting  : 'mjs-nestedSortable-no-nesting',
        handle          : 'div',
        items           : 'li',
        toleranceElement: '> div'
    });
});

function save_order(event)
{
   serialized = $('ol.sortable').nestedSortable('serialize');
    $.post({my_ajax_url}',serialized,function(data){
      alert('save!');
    });
}
Était-ce utile?

La solution

Just had to figure this out. Use the stop property. Something like...

$(document).ready(function(){
  $('.sortable').nestedSortable({
    disableNesting  : 'mjs-nestedSortable-no-nesting',
    handle          : 'div',
    items           : 'li',
    toleranceElement: '> div',
    stop: function() { save_order(); }
  });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top