N
N
Nikita Kit2018-07-19 16:56:33
JavaScript
Nikita Kit, 2018-07-19 16:56:33

How to make friends pagination with sorting in the table?

I have an array of strings in the format:

[{
  row: {
    cellName: {
      value: ""
    }
  }
}]

Each header cell contains a key that is equal to the key of the cell in row.
The sorting algorithm looks like this:
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

The tables have pagination, which is activated by adding the hideByPagi key to the array object if the array length is greater than the number of rows in one pagination page.
Sorting works correctly, but when trying to make friends with pagination, it causes bugs. I can't understand why
I tried:
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
...

In various combinations. None of them gave correct results.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-07-19
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question