Home

Awesome

v-pagy

Server-side paging component in vue, template based on bootstrap

Installation

npm install v-pagy

or via yarn

yarn add v-pagy

Example

<template lang="html">
  <pagination
    :total="total"
    :page-size="pageSize"
    :current-page="page"
    :options="options"
    @page-change="onPageChangedHandler"
    @refresh-page="onRefreshPageHandler"
    nav-class="padding-10"
    ul-class="bg-color-red"
    li-class="txt-color-blue"
  />
</template>

<script>
import pagination from 'v-pagy';

export default {
  components: {
    pagination,
  },
  props: {
    page: Number,
  },
  data() {
    return {
      total: 1000,
      pageSize: 20,
      options: { // Optional
        offset: 2,
        previousText: 'Prev',
        nextText: 'Next',
        alwaysShowPrevNext: true,
      },
    },
  },
  methods: {
    onPageChangedHandler(page) {
      console.log(page);
      // Exec your response to server passing 'page' params as clicked button paging
    },
    onRefreshPageHandler(page) {
      console.log(page);
      // Exec your response to server passing 'page' params as clicked on current active paging button
    },
  },
});
</script>

If you want to use HTML content for the first, last, previous and next button, there is some named slots. Here is an example:

<pagination
  :total="total"
  :page-size="pageSize"
  :current-page="page"
  :options="options"
  @page-change="onPageChangedHandler"
  @refresh-page="onRefreshPageHandler"
  nav-class="padding-10"
  ul-class="bg-color-red"
  li-class="txt-color-blue"
>
  <template slot="first-el">
    <span title="go first">◄◄</span>
  </template>
  <template slot="last-el">
    <span title="go last">►►</span>
  </template>
</pagination>

Events

Event nameArg TypeDescription
page-changenumberFire on click to the page link (except for the current one)
refresh-pagenumberFire on click to the current page link

props

NameTypeRequiredDefaultDescription
totalNumberYesTotal items from server side
pageSizeNumberYesNumber of items per page
callbackFunctionYesThe callback to be called on page changes
currentPageNumber1The current page from the URL params
optionsObjectConfigurations
navClassString''Class will be include in nav element
ulClassString''Class will be include in ul element
liClassString''Class will be include in all li element

options

NameTypeDefaultDescription
offsetNumber2Left and right offset of pagination numbers to display
ariaNextString'Next'Change default aria next text
ariaPreviousString'Previous'Change default aria previous text
ariaLastString'Last'Change default aria last text
ariaFirstString'First'Change default aria first text
previousTextString'‹'Change default previous button text
nextTextString'›'Change default next button text
firstTextString'«'Change default first button text
lastTextString'»'Change default last button text
alwaysShowPrevNextBooleantrueShow the prev/next button even if on the first/last page
alwaysShowFirstLastBooleantrueShow first/last button even if on first/last page
firstBooleantrueSet false to hide the first button
lastBooleantrueSet false to hide the last button
prevBooleantrueSet false to hide the previous button
nextBooleantrueSet false to hide the next button

slots

Useful in case you want to custom the UI of the first, last, previous and next buttons by HTML elements instead of using a text.

NameDescription
first-elCustom slot for the first link
prev-elCustom slot for the previous link
next-elCustom slot for the next link
last-elCustom slot for the last link