JQuery UI sortable: restore position based on some condition

前端 未结 3 1083
执念已碎
执念已碎 2020-12-14 11:57

I call sortable.stop() to make an ajax call to store some data after drag & drop operation.

When the ajax call returns an error (application logic e

相关标签:
3条回答
  • 2020-12-14 12:53

    Thanks, liveat60fps , its the second statement out of the two which you only need.

    $('#some-list').sortable({
    
          // other options here,
      receive: function(event, ui) {
    
        // ajax or function here
        if(somethingWentWrong) {
           $(this).sortable('cancel');
           $(ui.sender).sortable('cancel');
        }    
      }    
    });
    

    This way on a certain condition, you can revrt back to the orignal state.

    0 讨论(0)
  • 2020-12-14 12:55

    Have a look at .sortable('cancel'); something like this:

    var list = $('#some-list')
    list.sortable(
    {
        // Some options.
        stop: function()
        {
            $.post('some-url', someData, function()
            {
                if (somethingWentWrong)
                {
                    list.sortable('cancel');
                }
            });
        }
    });
    
    0 讨论(0)
  • 2020-12-14 12:55

    Thanks to dafi - this works for me:

    $('#some-list').sortable({
      // other options here,
      receive: function(event, ui) {
    
        // ajax or function here
        if(somethingWentWrong) {
           $(this).sortable('cancel');
           $(ui.sender).sortable('cancel');
        }
    
      }
    
     });
    

    I'm not sure if you need $(this).sortable('cancel');, but I figure it's best to cancel the source and the destination sortable lists. This way the list item reverts immediately. Other Sortable options here.

    0 讨论(0)
提交回复
热议问题