jquery ui sortable 实现table,row的拖动。(Make Table Rows Sortable Using jQuery UI Sortable)

// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
//console.log(ui)
ui.children().each(function() {
$(this).width($(this).width()); //在拖动时,拖动行的cell(单元格)宽度会发生改变。在这里做了处理就没问题了
});
return ui;
};


jQuery(function(){
jQuery("#hrCalendar tbody").sortable({ //这里是talbe tbody,绑定 了sortable
helper: fixHelper, //调用fixHelper
axis:"y",
start:function(e, ui){
ui.helper.css({"background":"#fff"}) //拖动时的行,要用ui.helper
return ui;
},
stop:function(e, ui){
//ui.item.removeClass("ui-state-highlight"); //释放鼠标时,要用ui.item才是释放的行
return ui;
}
}).disableSelection();
})

原文地址:https://www.cnblogs.com/zcm123/p/6108694.html