jquery-ui sortable:如何在拖动时不添加单元格
jquery-ui sortable: how not to add cells on dragging?
我有一些表格,例如:
<table class="table table-hover table-striped" id="mytable">
<thead>
<tr>
<th>#</th>
<th>Table heading 1</th>
<th>Table heading 2</th>
<th>Table heading 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
</tbody>
</table>
然后我想制作可排序表的行标题。
$('#mytable thead tr').sortable({
axis: "x",
helper: "clone"
}).disableSelection();
问题:
当我开始拖放时,我有 6 个 th
-s 而不是 4 个:
<tr class="ui-sortable">
<th>#</th>
<th style="
display: none;">Table heading 1</th>
<th class="ui-sortable-placeholder"
style="
visibility: hidden;"></th>
<th>Table heading 2</th>
<th>Table heading 3</th>
<th style="
display: table-cell;
width: 343px;
height: 37px;
position: absolute;
z-index: 1000;
left: 184px;"
class="ui-sortable-helper">Table heading 1</th>
</tr>
..所有的标记都开始变得非常不稳定和不确定:当我th
项目拖到桌子上时,我看到所有行的大小都在跳跃。
很明显,发生这种情况是因为th
项计数(不等于tr
中td
项的数量)。
如何修复?
每次开始拖动时,它都会创建两个新的th
元素。 一个没有显示,所以它似乎不会影响任何东西。第二个是原始元素的占位符,当您拖动它时。未设置此新元素的宽度,因此它会自动调整为列的最大宽度,这似乎是导致它跳来跳去的原因。
为了解决这个问题,我将占位符元素的宽度更改为我们在 start 函数中拖动的元素的宽度。希望这有帮助
start: function(event, ui){
$(".ui-sortable-placeholder").css({width: $(ui.item).width()});
下面是代码,这是我的小提琴
$(function () {
$('#mytable thead tr').sortable({
axis: "x",
helper: "clone",
start: function(event, ui){
$(".ui-sortable-placeholder").css({width: $(ui.item).width()});
}
}).disableSelection();
});
相关文章:
- 可以'我不明白为什么;t将行和单元格添加到表中
- 如何在Angular中的表的所有单元格中添加链接
- jQuery-通过AJAX调用动态添加具有值的表单元格
- dhtmlx添加新行并启动单元格编辑器
- ExtJ将工具提示添加到网格单元格文本中
- 用于在表中添加行的Javascript代码将单元格中的数据复制到新行中
- 将工作表复制到新的电子表格,将单元格值添加到新电子表格名称的末尾
- 将类添加到 html 表的特定单元格
- 如何在 CKEditor 表的单元格属性中添加新属性
- jquery-ui sortable:如何在拖动时不添加单元格
- jQuery将文本添加到放置在表格单元格中的图像中
- 如何在 D3.grid 示例中向单元格添加文本 D3-js-building-a-grid-of-矩形
- Javascript- 将点击事件添加到动态生成的表格单元格中
- JQuery 更新表单元格并添加新的表行
- 将悬停CSS添加到用javascript处理的表单元格中
- 如何在表格单元格中添加图像
- 如何通过每行中动态添加的按钮更改 HTML 表格单元格值
- 如何使用javascript在不同的表格单元格中添加不同的图标
- 如何在添加行时添加单元格样式并更改
的属性 - 通过Javascript函数动态创建一个表并向表中添加单元格