Files
EdgeAdmin/web/public/js/components/common/sortable.js

40 lines
969 B
JavaScript
Raw Normal View History

2020-09-28 16:25:26 +08:00
// 给Table增加排序功能
function sortTable(callback) {
// 引入js
let jsFile = document.createElement("script")
jsFile.setAttribute("src", "/js/sortable.min.js")
jsFile.addEventListener("load", function () {
// 初始化
let box = document.querySelector("#sortable-table")
2020-10-08 11:11:37 +08:00
if (box == null) {
return
}
2020-09-28 16:25:26 +08:00
Sortable.create(box, {
draggable: "tbody",
handle: ".icon.handle",
onStart: function () {
},
onUpdate: function (event) {
let rows = box.querySelectorAll("tbody")
let rowIds = []
rows.forEach(function (row) {
rowIds.push(parseInt(row.getAttribute("v-id")))
})
callback(rowIds)
}
})
})
document.head.appendChild(jsFile)
2021-09-29 20:12:27 +08:00
}
function sortLoad(callback) {
let jsFile = document.createElement("script")
jsFile.setAttribute("src", "/js/sortable.min.js")
jsFile.addEventListener("load", function () {
if (typeof (callback) == "function") {
callback()
}
})
document.head.appendChild(jsFile)
}