JQueryUI可排序thead和tbody在拖动行时隐藏了两个字段

Llu*_*rer 9 javascript css jquery jquery-ui draggable

我有一个包含不同行和字段的表.在一行中我有两个字段,display:none;当我拖动这些行时,有一个效果,如横向填充<tbody><thead>,表没有收缩,表的元素是.

在第一行中的下一个JsFiddle无法正常工作,但在第二行中只有一个字段display:none;可以正常工作.

如果有任何问题请问.

错误的例子 在此输入图像描述

拖动时表:

在此输入图像描述

起初我以为可以通过查找<td>具有类的类的数量.hidden-td(具有a的类display: none;)并查找具有类的元素.placeholder-style(具有<tr>在执行拖动时生成的类)并且添加许多来解决它<td>因为<tr>我正在移动,但不是,不起作用.

我知道.hidden-td这条线有多少字段

var numcells = $('.hidden-td').length;

问题

我在第一行中有9个元素,在另一个中我有8个.在我的函数中start()我只在我的占位符中隐藏了一列,所以当我拖动第一行时,剩下一列没有应用类.hidden-td,这就是为什么有一个列末尾的空格.

我怎样才能解决这个问题?

https://jsfiddle.net/w52m5ggb/20/

Hug*_*ing 2

在过去的几天里,我自己一直在与可排序插件作斗争,我认为需要进行以下更改:

  1. 添加帮助器函数以在帮助器(可拖动对象)上创建正确的大小,以获得正确的大小。

  2. 在开始函数中,将项目 html 添加到占位符 html 中,以使占位符与原始内容保持相同。

代码:

$("#tbodyproject").sortable({
    items: "> tr",
    appendTo: "parent",
    helper: "clone",
    placeholder: "placeholder-style",
    start: function(event, ui) {
      $(this).find('.placeholder-style td:nth-child(2)').addClass('hidden-td')

      //copy item html to placeholder html

      ui.placeholder.html(ui.item.html());

      //hide the items but keep the height/width. 
      ui.placeholder.css('visibility', 'hidden');
    },
    stop: function(event, ui) {
        ui.item.css('display', '')
    },

    //add helper function to keep draggable object the same width
    helper: function(e, tr)
    {
        var $originals = tr.children();
        var $helper = tr.clone();
        $helper.children().each(function(index)
        {
        // Set helper cell sizes to match the original sizes
        $(this).width($originals.eq(index).width());
        });
        return $helper;
    },
    update: function( event, ui ) {
        let newOrder = $(this).sortable('toArray');
        $.ajax({
            type: "POST",
            url:'/admin/projects/updateOrder',
            data: {ids: newOrder}
        })
       .done(function( msg ) {
        location.reload();        
       });
    }
}).disableSelection();
Run Code Online (Sandbox Code Playgroud)

更新了小提琴