Answer the question
In order to leave comments, you need to log in
How to make friends pagination with sorting in the table?
I have an array of strings in the format:
[{
row: {
cellName: {
value: ""
}
}
}]
resort = (array) ->
return array.sort (a, b) ->
if typeof a.row[that.currentSort.value].value == 'number' && typeof b.row[that.currentSort.value].value == 'number'
modifier = 1
if that.currentSort.dir == 'desc'
modifier = -1
if a.row[that.currentSort.value].value < b.row[that.currentSort.value].value
return -1 * modifier
if a.row[that.currentSort.value].value > b.row[that.currentSort.value].value
return 1 * modifier
return 0
else
console.log("sort like strings: ", a.row[that.currentSort.value].value, b.row[that.currentSort.value].value)
modifier = 1
if that.currentSort.dir == 'desc'
modifier = -1
if a.row[that.currentSort.value].value.toLowerCase() < b.row[that.currentSort.value].value.toLowerCase()
console.log('return: ', -1 * modifier)
return -1 * modifier
if a.row[that.currentSort.value].value.toLowerCase() > b.row[that.currentSort.value].value.toLowerCase()
console.log('return: ', 1 * modifier)
return 1 * modifier
console.log('return 0')
return 0
return array.sort (a, b) ->
if a.hideByPagi && b.hideByPagi
return 0
if a.hideByPagi && !b.hideByPagi
return 1
if b.hideByPagi && !a.hideByPagi
return -1
...
Answer the question
In order to leave comments, you need to log in
You can do
or
And you have something strange.
(Wangyu that the first option is preferable. But this is not certain.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question