i have done the following now:
I have overwritten the default sort (actually with the same code as the default table sort) and added the __sortedIndex:
tableSort (data, sortBy, descending) {
const col = this.columns.find(def => def.name === sortBy)
if (col === null || col.field === void 0) {
let sortedStuff = data.slice().map((row, i) => {
row.__sortedIndex = i
return row
})
return sortedStuff
}
const dir = descending ? -1 : 1,
val = typeof col.field === 'function' ? v => col.field(v) : v => v[col.field]
let sorted = data.sort((a, b) => {
let A = val(a),
B = val(b)
if (A === null || A === void 0) {
return -1 * dir
}
if (B === null || B === void 0) {
return 1 * dir
}
if (col.sort) {
return col.sort(A, B) * dir
}
if (isNumber(A) && isNumber(B)) {
return (A - B) * dir
}
if (isDate(A) && isDate(B)) {
return sortDate(A, B) * dir
}
if (typeof A === 'boolean' && typeof B === 'boolean') {
return (a - b) * dir
}
[A, B] = [A, B].map(s => (s + '').toLowerCase())
return A < B ? -1 * dir : A === B ? 0 : dir
})
let sortedStuff = sorted.slice().map((row, i) => {
row.__sortedIndex = i
return row
})
return sortedStuff
}
It would be nice to have a callback after sorting is done so we can add the __sortedIndex in this case so its not necessary to re-code the default sorting.
also i am watching the selected rows change, and the pagination object change and select the page in the pagination object. this is done by using the default __index if not sorted and if available the __sortedIndex:
selectedRows (what) {
if (what.length > 0) {
let idx = what[0].__index + 1
if (what[0].__sortedIndex) {
idx = what[0].__sortedIndex + 1
}
let newPage = idx / this.paginationControl.rowsPerPage
this.paginationControl.page = Math.ceil(newPage)
} else {
this.paginationControl.page = 1
}
}
It somehow works even with filtering, what i dont understand.
do you have any better solution to this or do you see any problems here?
Thanks for the help and Cheers!