问题描述
我正在使用可排序的jQuery UI,以使我的表网格可排序.该代码似乎可以正常工作,但是因为我没有在td
s中添加宽度,所以当我拖动tr
时它会缩小内容.
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 td
s, when I drag the tr
it shrinks the content.
例如;如果我开始拖动时表格行为500px,则该行变为300px.我认为这是因为没有在网格中定义宽度而发生的.那是因为我正在为td
使用两个类(fix
和liquid
).
For example; if my table row is 500px when I start dragging, it becomes 300px. I assume that's happening because no width is defined in the grid. That's because I am using two classes for the td
s (fix
and liquid
).
fix
类使td
等于内容宽度,而liquid
使td
宽度为100%.这是我的网格表方法,无需为td
s分配宽度.
The fix
class makes the td
equal to the content width and liquid
makes the td
width 100%. It's my approach for grid table without having to assign width to td
s.
有什么主意如何利用我的方法进行可排序的工作?
Any idea how to make sortable work with my approach?
推荐答案
我找到了答案此处.
我稍作修改以克隆行,而不是在原始行上增加宽度:
I modified it slightly to clone the row, instead of adding widths to the original:
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;
},
这篇关于jQuery UI Sorting with table and tr width的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!