Code Monkey home page Code Monkey logo

pagination-helper's Introduction

pagination-helper

CI

a simple pagination for calculating offset, limit and number of pages

Installation and Usage

Server-side usage

Install the library with npm install pagination-helper

yarn

yarn add pagination-helper

No ES6

var paginationHelper = require('pagination-helper');

ES6

import paginationHelper from "pagination-helper";

let pagination = new paginationHelper({
    data_per_page: 10 // number of data that you want to show them per page
})

console.log(pagination.getNumberOfPages(209)) // => 21, it means that you have 21 pages
console.log(pagination.getNumberOfPages(20.9)) // => 3, it means that you have 3 pages, it support the float numbers.

React

if you want to map number of your page's in your react component you can go on like this:

import paginationHelper from "pagination-helper";

let pagination = new paginationHelper({
    data_per_page: 10, // number of data that you want to show them per page
    exportDataAsarray: true // export number of pages as array
})

console.log(pagination.getNumberOfPages(20.9)) // => [ 1, 2, 3 ]

Get Page Number by Offset And Limit

console.log(pagination.getPageNumberByOffsetAndLimit(30, 5)) // => 7, it means you are in page 7

Get Offset(Limit) And Limit(Take) by Page Number

this method give you the number of your (take, skip) by page number, it's useful for when you want to write a query to get the data

console.log(pagination.getTakeAndSkip(7)) // => { take: 10, skip: 60 }, it means, if you want to go to page 7 set this data
// to your query

Maintainers

pagination-helper's People

Stargazers

 avatar  avatar

Watchers

 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.