表行上的jQueryUI可以在拖动时收缩它们

Yos*_*ssi 15 jquery jquery-ui html-table shrink jquery-ui-sortable

在可排序函数中拖动时,这个表行缩小的问题让我困扰了很长时间.有答案吗?(Q&A)

PS为了可以在表上进行排序,你必须在要排序的表行周围使用TBODY,然后调用包含TBODY的可排序函数.

小智 39

.ui-sortable-helper {
    display: table;
}
Run Code Online (Sandbox Code Playgroud)


Yos*_*ssi 12

您需要做的就是为表格单元格提供特定的像素宽度.如果不知道表格单元格的内容,我们怎么做呢?简单:

$(document).ready(function(){
    $('td').each(function(){
        $(this).css('width', $(this).width() +'px');
    });
});
Run Code Online (Sandbox Code Playgroud)

  • "更好"的方法是[stackoverflow](http://stackoverflow.com/a/1372954/1057527) (2认同)
  • 我喜欢这种方法.比'更好'的更好. (2认同)

bmo*_*ran 10

我在网上偶然发现了一个解决方案.

var fixHelper = function(e, ui) {  
  ui.children().each(function() {  
    $(this).width($(this).width());  
  });  
  return ui;  
};
$(“#sort tbody”).sortable({  
 helper: fixHelper  
 }).disableSelection();
Run Code Online (Sandbox Code Playgroud)

修复可收缩的tr收缩