question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fixed : b-pagination not working with v-for, only works with b-table

See original GitHub issue

b-pagination or b-pagination-nav not working with v-for only works with b-table please give a example b-pagination or b-pagination-nav works with <div v-for="item in items>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

25reactions
tmorehousecommented, Nov 5, 2018

Ah, the per-page only applies to the pagination component. You need to slice your data when presenting it to your v-for loop (you are currently giving it the entire list)

<template>
  <div  v-for="list in lists" :key="list.id">
    {{ list.name }}
  </div>
  <b-pagination
     :total-rows="totalRows" 
     v-model="currentPage"
     :per-page="perPage"
  />
</template>
<script>
export default {
  data () {
    return { 
      currentPage: 1,
      perPage: 5,
    }
  },
  computed: {
    lists () {
      const items = this.$store.getters.loadedLists
      // Return just page of items needed
      return items.slice(
        (this.currentPage - 1) * this.perPage,
        this.currentPage * this.perPage
      )
    },
    totalRows () {
      return this.$store.getters.loadedLists.length
    }
  }
}
</script>
3reactions
Codefacommented, Nov 5, 2018

@tmorehouse Thank you very much i just forgot to use some logics and i did it with <b-pagination-nav works fine (actually i want to link routes too ) working code here 👍 for who thinks its hard to implement pagination with router links here perPage = 2 & number-of-pages=5 (number-of-pages is a computed property ) beacuse i have only 10 items and i want to show it 2 / page so 5 * 2 = 10 10 is the total number of items comes from vuex store

<template>
<div id="lists">
  <div  v-for="list in lists" :key="list.id">
    {{ list.name }}
  </div>
</div>
<b-pagination-nav :link-gen="linkGen" :number-of-pages="numPages" v-model="currentPage" />
</template>

<script>
export default {
  data () {
    return { 
      currentPage: 1,
      perPage: 2
    }
  },
computed: {
    lists () {
      const items = this.$store.getters.loadedLists
      // Return just page of items needed
      return items.slice(
        (this.currentPage - 1) * this.perPage,
        this.currentPage * this.perPage
      )
    },
    numPages () {
      return Math.ceil(this.$store.getters.loadedLists.length / this.perPage)
    }
  },
  methods: {
    linkGen (pageNum) {
      return '#page=' + pageNum
    }
  }
}
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Impossible to build vuejs app - pagination error - Stack Overflow
I'm using this code but it will not work. How I can fix it? HTML for pagination <div class="col-1 text-center p-0 feed ...
Read more >
Building Table Sorting and Pagination in Vue.js
External JavaScript​​ I'm just using the sort method of my array with the property being dynamic. The modifier bit just handles reversing the ......
Read more >
Table | Components - BootstrapVue
For displaying tabular data, <b-table> supports pagination, filtering, sorting, custom rendering, various style options, events, and asynchronous data.
Read more >
Table | Quasar Framework
The QTable Vue component allows you to display data in a tabular manner and it's packed with a lot of related features. It's...
Read more >
v-data-table API - Vuetify
Fixed header to top of table. NOTE: Does not work in IE11. #footer-props ... Currently only supports a single grouping in the format:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found