Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

拖拽前置事件 #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion ext/soulTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,36 @@ layui.define(['table', 'tableFilter', 'tableChild', 'tableMerge'], function (exp
}
});

var newIndex = $this.index();
var newIndex = $this.index();
//前置事件
if (typeof myTable.rowDrag.before === 'function') {
if( newIndex !== index ) {
var cache = layui.table.cache[tableId]
// flag == false 取消拖拽
var flag = myTable.rowDrag.before.call(myTable, {
row: cache[index],
newIndex: newIndex,
oldIndex: index,
before:newIndex > index ? cache[newIndex]:cache[newInde - 1],
after:newIndex > index ? cache[newIndex + 1] : cache[newIndex],
cache: cache
})
if (!flag) { // 取消拖拽
if(index > newIndex){
$bodyTr.insertAfter($bodyTr.parent().find("tr").eq(index))
}
if(index < newIndex){
$bodyTr.insertBefore($bodyTr.parent().find("tr").eq(index))
}
//修正index
$bodyTr.parent().find("tr").each(function(index, item){
$(item).data('index', index);
$(item).attr('data-index', index);
})

}
}
}
if (newIndex !== index) { // 有位置变动
if (typeof myTable.rowDrag.done === 'function') {
var cache = layui.table.cache[tableId],
Expand Down