implement on-demand numerical sort in dyntables

alfred
Josha von Gizycki 3 years ago
parent a52c15649e
commit 8d92817e15

@ -237,13 +237,13 @@ document.addEventListener('DOMContentLoaded', function () {
function onSort(ctx, ix, event) {
const tbl = ctx.tbl
const sortDir = event.target.getAttribute('data-sort') || 'asc'
const sortMod = sortDir === 'asc' ? -1 : 1;
const rows = tblRows(tbl)
const newTbody = document.createElement('tbody')
rows.sort((row1, row2) => {
const val1 = row1.cells[ix].textContent
const val2 = row2.cells[ix].textContent
@ -251,10 +251,10 @@ document.addEventListener('DOMContentLoaded', function () {
: val2 > val1 ? -1
: 0);
})
rows.forEach(row => newTbody.appendChild(row))
tbl.replaceChild(newTbody, tbl.tBodies[0])
clearSortAttributes(tbl)
event.target.setAttribute('data-sort', flipSortDir(sortDir))
changePage(ctx, 0)

Loading…
Cancel
Save