11
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

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

何が問題か

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
    });
});

デモ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
11
Help us understand the problem. What are the problem?