reactive-table
reactive-table copied to clipboard
sorting breaks when using fn
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}}
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
Hmm, I think something + Infinity is still Infinity, so I don't think that's the problem.
but can you slice with infinity? I get an empty array if I pass infinity as my second argument.
The problem is skip ends up being NaN - it's currentPage (0) * rowsPerPage (Infinity)
Exactly. I replaced infinity with Number. MAX_SAFE_INTEGER and it works like a charm