拖拽时Jquery可排序表收缩

时间:2018-02-16 07:29:15

标签: jquery jquery-ui jquery-ui-sortable

我的问题是桌子在拖动时会缩小。行仍然是它的宽度,但表缩小。有没有办法在拖动时保持表格的原始宽度?

Example is here

使用以下方式调用可排序功能:

 $("table[id=tblSelectedCAMERC] tbody").sortable();

enter image description here

2 个答案:

答案 0 :(得分:1)

<table>元素使用Sortable时,有时最好准确定义item的内容。请查看:http://api.jqueryui.com/sortable/#option-items

我会建议如下:

$(function(){  
  $("table[id=tblSelectedCAMERC] tbody").sortable({
    sort: function(evt, ui){
      debugger;
    },
    item: "> tr",
    handle: ".iORAS_ORD"
  }).disableSelection();
});

<强>更新

由于有一些额外的细胞,你可以这样做:

<强> CSS

.shrink td:last-child {
  display: none;
}

<强>的JavaScript

$(function(){  
  $("table[id=tblSelectedCAMERC] tbody").sortable({
    sort: function(evt, ui){
      debugger;
    },
    items: "> tr",
    handle: ".iORAS_ORD",
    scroll: true,
    tolerance: "intersect",
    placeholder: "shrink"
  }).disableSelection();
});

请记住,占位符类已应用于项目,在本例中为<tr>。因此,如果我们需要抑制或隐藏某些单元格,我们需要选择它们。此示例假定有1个额外单元格。如果你有更多的单元格,我会建议为它们添加一个类(E.G。:hidden),这样你就可以更容易地选择它们。您还可以尝试其他CSS选择器(https://www.w3schools.com/cssref/css_selectors.asp

答案 1 :(得分:1)

在样式表中添加:

.ui-sortable-helper {
display: table;

}