Coder Social home page Coder Social logo

lostkobrakai / vue-pagination-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matfish2/vue-pagination-2

0.0 3.0 0.0 50 KB

Vue.js 2 pagination component

Home Page: https://www.npmjs.com/package/vue-pagination-2

License: MIT License

JavaScript 100.00%

vue-pagination-2's Introduction

Vue Pagination 2

Click here to see it in action.

Note: This package is for use with Vuejs 2. For version 1 please use v-pagination instead.

Simple, generic and non-intrusive pagination component for Vue.js version 2.

Dependencies

  • Vue.js (>=2.0.0-rc.1). Required.
  • CSS: Bootstrap 3 or Bootstrap 4 or Bulma.

Installation

NPM

npm install vue-pagination-2

import the script:

import {Pagination} from 'vue-pagination-2';

Script tag

Grab the minified version under dist/vue-pagination-2.min.js. It will export a global Pagination variable.

Usage

Register the component globally or locally:

Vue.component('pagination', Pagination);

OR

...
components: {
  Pagination
}
...

HTML:

<pagination :records="500" @paginate="myCallback"></pagination>

props:

  • for string optional unique identifier for the component instance.

  • records number required number of records

  • per-page number optional records per page. Default: 25

  • chunk number optional max pages per chunk. Default: 10

  • vuex boolean optional Use vuex to manage state. Default: false

  • theme string CSS theme used for styling. Supported: bootstrap3, bootstrap4,bulma. Default: bootstrap3.

  • format boolean optional Format numbers using a separating comma. Default: true

  • count-text string optional total records text. It can consist of up to 3 parts, divided by |.

    • First part: used when there are multiple pages
    • Second part: used when there is only one page
    • Third part: used when there is only one record.

    Default: Showing {from} to {to} of {count} records|{count} records|One record

Handle page selection

Custom Event

When a page is selected a custom paginate event will be dispatched. Listen to it on the component and run your callback

Event bus

Note: To use this option you must:

A. Provide a unique identifier using the for prop B. Import the pagination event bus along with the component itself:

import {Pagination,PaginationEvent} from 'vue-pagination-2'

When a page is selected the bus will dispatched an event, using the unique id for the component. Listen to it on your bus and respond accordingly:

PaginationEvent.$on('vue-pagination::some-entity', function(page) {
    // display the relevant records using the page param
});

Vuex (>=2.0.0)

Note: To use this option you must provide a unique identifier using the for prop.

The component will register a module on your store using the for prop as the name. The module will have a page property that will contain the current page. vue-devtools will give you a nice overview of the data structure.

If you want to latch on to an existing module on your store, use its name in the for prop and manuaully add the following to you store:

{
  myModule:{
    state:{
    ```
      page: 1
    ```
  },
  mutations: {
       ```
       ['myModule/PAGINATE'](state, page) {
              state.page = page
          }
      ```
    }
  }

Programmatic Manipulation

To programmatically set the page apply a ref identifier to the component and use one of the following methods:

  • setPage(page)
  • next()
  • prev()
  • nextChunk()
  • prevChunk()

All methods return true if the page is legal and was thus set, or false otherwise.

Computed Properties

  • totalPages
  • totalChunks
  • currentChunk

vue-pagination-2's People

Contributors

matfish2 avatar kramin42 avatar sebastians90 avatar

Watchers

James Cloos avatar Benjamin Milde avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.