Filter seems to break pagination
amwhalen opened this issue · comments
I've slightly modified the demo example code given in the documentation of the IMDB search with pagination to illustrate the problem. I added a simple filter to the options given to itemsjs.search, and the result is that clicking past page 1 does not show any results. This was the only change I made to the example code:
filter: (item) => { return item.year > 1994; }
Fiddle here: https://jsfiddle.net/awhalen/5wmL9jv2/
Perhaps I'm misusing or misunderstanding filter, or maybe I should use prefilter (which doesn't actually seem to do anything?). Thanks.
A little investigation reveals that when calling .search, making sure there is a sort options specified makes it work as intended. The demo did not specify a sort option. Here is updated code that appears to function correctly:
var result = itemsjs.search({
query: this.query,
page: this.page,
per_page: 12,
filters: this.filters,
sort: 'name_asc',
filter: (item) => {
return item.year > 1994;
}
})