LoginSignup
18
12

More than 5 years have passed since last update.

jQuery UIのSortableをTableで使用した際の横幅縮小を解消する方法

Last updated at Posted at 2017-05-15

何が問題か

Sortableは、Tableタグでドラッグした際に横幅が小さくなる現象が発生します。
Tableタグ以外を使えばいいのですが、結構Tableで組みたいことも多いと思います。
そこで、Tableタグで横幅が小さくなる現象を解消します。

実装

これを入れれば解決

$(function(){
    function fixPlaceHolderWidth(event, ui){
        // adjust placeholder td width to original td width
        ui.children().each(function(){
            $(this).width($(this).width());
        });
        return ui;
    };

    $('.sortable').sortable({
        placeholder: 'ui-state-highlight',
        start: function(event, ui){
            ui.placeholder.height(ui.helper.outerHeight());
        },
        helper: fixPlaceHolderWidth
    });
});

デモ

18
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
12