I have a search input that I use to filter an array of users that are shown in a table. This table includes pagination so I’m using .slice to get 10 users to show on the table per page. For some reason, the search filtering works if I’m on page 1 (guessing because there’s no slice on page 1?); after going to another page, the filtering stops working, this is to do with .slice since it works if I remove the .slice code. Any ideas why this is? There’s something I’m not seeing here..
tableData() { return this.users .filter( (user) => user.firstName.toLowerCase().includes(this.search.toLowerCase()) || user.lastName.toLowerCase().includes(this.search.toLowerCase()) || user.email.toLowerCase().includes(this.search.toLowerCase()), ) .slice(this.perPage * (this.currentPage - 1), this.perPage * this.currentPage); },
Advertisement
Answer
It s because your result is now on the first page or somewhere before.
You are slicing the result.