Skip to content

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