aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 138 forks source link

sorting breaks when using fn #405

Open SimonVuong opened 8 years ago

SimonVuong commented 8 years ago

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 commented 8 years ago

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

aslagle commented 8 years ago

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

SimonVuong commented 8 years ago

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

aslagle commented 8 years ago

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

SimonVuong commented 8 years ago

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