Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent negative value for currentPage #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

patrickkivits
Copy link

When given an empty list, the value of currentPage becomes -1.

Even when you then update the empty list with an item, the items still won't show up.

This pull request ensures there can never be a negative value for the currentPage and it will always have an minimum value of 0.

Fixes: #94

@JeremyLopez
Copy link

I found a hacky workaround that fixed it for my app. First, I added a ref to my <paginate></paginate> component ref="paginator". Then I created a computed property:

emptyArray () {
 return store.state.recipes.length == 0
}

then I created a watcher that looks for a change from length == 0 to length != 0:

watch: {
      emptyArray: function(newVal, oldVal) {
        if ( newVal === false && oldVal === true ) {
          setTimeout(() => {
            if (this.$refs.paginator) {
              this.$refs.paginator.goToPage(page)
            }
          }, 100)
        }
      }
    }

The timeout was necessary otherwise it thought there was no page 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants