主要的代碼看起來像下面。
sort : function(event, ui) {
var $helper = $('.ui-sortable-helper'), hTop = $helper.offset().top, hStyle = $helper.attr('style'), hId = $helper.attr('id');
if (first_rows.length > 1) {
$.each(first_rows, function(i, item) {
if (hId != item.id) {
var _top = hTop + (26 * i);
$('#' + item.id).addClass('ui-sortable-helper').attr('style', hStyle).css('top', _top);
}
});
}
},
start : function(event, ui) {
if (ui.item.hasClass('ui-selected') && $('.ui-selected').length > 1) {
first_rows = $('.ui-selected').map(function(i, e) {
var $tr = $(e);
return {
tr : $tr.clone(true),
id : $tr.attr('id')
};
}).get();
$('.ui-selected').addClass('cloned');
}
ui.placeholder.html('<td colspan="99"> </td>');
},
stop : function(event, ui) {
if (first_rows.length > 1) {
$.each(first_rows, function(i, item) {
$(item.tr).removeAttr('style').insertBefore(ui.item);
});
$('.cloned').remove();
first_rows = {};
}
$("#uber tr:even").removeClass("odd even").addClass("even");
$("#uber tr:odd").removeClass("odd even").addClass("odd");
}
我不知道我理解你想要什麼,反正什麼代碼實際上做的是:
從第一臺
- ,選擇多個項目;
- 通過按住懸停其中一個選定項目;
- 您可以在列表中將所選的任意位置移動;
- 維護所有選定項目的排序順序;
希望這是你在找什麼。由馬修·安德森創建
檢查這個插件:https://github.com/iamvery/jquery.multisortable這問題有一個解決方案,使用可拖動和droppable:http://stackoverflow.com/questions/3774755/jquery-sortable-select-and-drag-multiple-list-items – jfrej
謝謝,但我仍然想使用可排序和selectab le有所有可用的功能 – Ruben
@Ruben:嗨,你說克隆是越野車,但你看到我的例子嗎?它對我很好。你怎麼看? –