使用 JQuery UI 进行表格排序:
http://jsfiddle.net/bgrins/tzYbU/
您可以应用自己的 CSS 来创建您想要的任何外观。请注意,这不支持父子关系。
支持父子关系的东西是一个 JQuery 'treeTable' 插件,位于:https ://github.com/ludo/jquery-treetable
这是一个实现 treeTable 插件的 jsFiddle:http:
//jsfiddle.net/mccannf/Tbd38/10/
使用相当简单的代码:
$(document).ready(function() {
$("#dragndrop").treeTable({
expandable: false
});
// Drag & Drop Code
$("#dragndrop .entry").draggable({
helper: "clone",
opacity: .75,
refreshPositions: true, // Performance?
revert: "invalid",
revertDuration: 300,
scroll: true
}
);
$("#dragndrop .entry").each(function() {
$($(this).parents("tr")[0]).droppable({
drop: function(e, ui) {
$($(ui.draggable).parents("tr")[0]).appendBranchTo(this);
setNewParent($($(ui.draggable).parents("tr")[0]).attr("id"), $(this).attr("id"));
},
hoverClass: "accept",
over: function(e, ui) {
if(this.id != $(ui.draggable.parents("tr")[0]).id && !$(this).is(".expanded")) {
$(this).expand();
}
}
});
});
function setNewParent(child, parent)
{
// do ajax call here
//alert(child);
//alert(parent);
}
});
这个插件的主要缺点:
- 您不能对处于同一级别的节点重新排序。
- 您不能将节点直接移动到最顶层。
有时间的人可能会分叉插件并将这些功能添加到其中。