[英]JQuery Sortable with fixed row
$("#sortable").sortable({
cancel: ".fixed"
});
$("#sortable").disableSelection();
在此示例中,项目3,5是固定的,但是当我将项目7移至项目3上方时,项目3将其位置更改为4,我希望它保持在第三位置(项目3和项目7),其余项目可以拖放由用户。 我如何实现此功能?
一半解决方案是http://jsfiddle.net/wa1grxrh/1/
$("#sortable").sortable({
cancel: ".fixed",
start: function(event, ui) {
var start_pos = ui.item.index();
ui.item.data('last_pos', start_pos);
},
change: function(event, ui) {
var last_pos = ui.item.data('last_pos'),
index = ui.placeholder.index(),
options = $(this).data().sortable.options;
if (last_pos > index) {
$(options.items, $(this)).slice(index, last_pos + 1).filter(options.cancel).each(function(ix) {
$(this).prevAll().not('.ui-sortable-placeholder').first().detach().insertAfter(this);
});
} else if (last_pos < index) {
$(options.items, $(this)).slice(last_pos, index + 1).filter(options.cancel).each(function(ix) {
$(this).nextAll().not('.ui-sortable-placeholder').first().detach().insertBefore(this);
});
}
ui.item.data('last_pos', ui.placeholder.index());
},
});
$("#sortable").disableSelection();
但是,如果任何固定项目位于第一个或最后一个,或者连续有多个固定项目,则无法使用。
我很想修改排序模块需要完整的解决方案。 需要防止占位符放在固定项目之间或项目列表的边缘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.