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

前端 未结 9 738
后悔当初
后悔当初 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:08

    What you can do is create a row that is invisible to the "sortable" mechanism. Probably the easiest way to do this is with the "items" option.

    Let's say your HTML looks like this

    
        stuff
        stuff
        stuff
        
    
    

    Then in jquery you can have

    $('.sortable').sortable({
        items: ">*:not(.sort-disabled)"
    });
    

    It's a bit of a hack, but I think if you play around with variations of this (give the .sort-disabled row some height in CSS etc.) you can probably find something that works for you. You could also try having a .sort-disabled row both first and last, so that the place in the middle is the drop target.

    Hope this helps!

提交回复
热议问题