Jquery ui-sortable - unable to drop tr in empty tbody

前端 未结 9 733
后悔当初
后悔当初 2021-02-01 19:43

I have two connected tbody elements allowing me to drag rows between two tables. Everything works fine until all rows are removed from either table.

When all rows have

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 20:12

    Here's how I solved the issue with being unable to drop a tr in an empty tbody:

    $(function() {
    
        var sort1 = $('#sort1 tbody');
        var sort2 = $('#sort2 tbody');
    
       sizeCheck(sort1);
       sizeCheck(sort2);
    
       //Start the jQuery Sortable for Active and Fresh Promo Tables
       $("#sort1 tbody, #sort2 tbody").sortable({
    
         items: ">*:not(.sort-disabled)",
    
         deactivate: function(e, ui) {
    
            sizeCheck(sort1);
            sizeCheck(sort2);
    
         },
         //Connect tables to pass data
         connectWith: ".contentTable tbody"
    
       }).disableSelection();
    
    });
    
    //Prevent empty tbody from not allowing items dragged into it
    
    function sizeCheck(item){
        if($(item).height() == 0){
            $(item).append('');
        }
    }
    

提交回复
热议问题