jquery UI Sortable with table and tr width

前端 未结 12 771
不知归路
不知归路 2020-11-28 18:02

I am using jQuery UI sortable to make my table grid sortable. The code seems to work fine but because I am not adding width to tds, when I drag the tr

12条回答
  •  醉梦人生
    2020-11-28 18:40

    jsFiddle

    After a lot of different attempts I just tried a simple solution which completes the solution of Dave James Miller to prevent the table of shrinking while dragging the largest row. I hope it will helps :)

    // Make sure the placeholder has the same with as the orignal
    var start = function(e, ui) {
        let $originals = ui.helper.children();
        ui.placeholder.children().each(function (index) {
            $(this).width($originals.eq(index).width());
        });
    }
    // Return a helper with preserved width of cells
    var helper = function(e, tr) {
        let $helper = tr.clone();
        let $originals = tr.children();
        $helper.children().each(function (index) {
            $(this).width($originals.eq(index).outerWidth(true));
        });
        return $helper;
    };
    

提交回复
热议问题