0

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);
    },

1 Answer 1

1

It s because your result is now on the first page or somewhere before.

You are slicing the result.

Sign up to request clarification or add additional context in comments.

4 Comments

What's a way I could fix the issue if this is the case?
When you are searching, the table is resizing. Maybe you should bring back the user on the first page when he is typing something.
Thanks i'll try it
That worked. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.