reactive-table icon indicating copy to clipboard operation
reactive-table copied to clipboard

sorting breaks when using fn

Open SimonVuong opened this issue 9 years ago • 5 comments

i cannot for the life of me figure why it's breaking when i try to sort by fn. the collection is defined in common code. i am using autopublish and insecure packages. the collection stores multiple fields and i am only trying to get 1 field to display in my table currently.

Client side:

Template.hello.helpers({
 collection () {
    return myCollection.find({});
  },

  fields () {
    return [
      {
        key: 'name',
        label: 'Name',
        fn: function (value,object,key) {
          return value;
        }
      }
    ]
 },

  settings () {
    return {
      rowsPerPage: Infinity,
      showNavigationRowsPerPage: false,
      showNavigation: 'never',
      showFilter: false,
      multiColumnSort: false,
      class: 'ui fluid selectable compact small unstackable striped fixed ' +
      'single line celled table'
     }
  }
})

{{> reactiveTable collection=collection fields=fields settings=settings}}

SimonVuong avatar Jun 24 '16 04:06 SimonVuong

the error is because rowsPerPage = Infinity. cannot use infinity if you intend to sort by fn because sort logic is...

            sortedRows = sortWithFunctions(rows, this.fields, this.multiColumnSort);
            return sortedRows.slice(skip, skip + limit);

and skip + limit = NaN since limit = infinity

SimonVuong avatar Jun 24 '16 04:06 SimonVuong

Hmm, I think something + Infinity is still Infinity, so I don't think that's the problem.

aslagle avatar Jun 25 '16 21:06 aslagle

but can you slice with infinity? I get an empty array if I pass infinity as my second argument.

SimonVuong avatar Jun 25 '16 23:06 SimonVuong

The problem is skip ends up being NaN - it's currentPage (0) * rowsPerPage (Infinity)

aslagle avatar Jun 26 '16 02:06 aslagle

Exactly. I replaced infinity with Number. MAX_SAFE_INTEGER and it works like a charm

SimonVuong avatar Jun 26 '16 02:06 SimonVuong