pl

pagination-logic

Pure Javascript pagination logic without UI component

Showing:

Popularity

Downloads/wk

4

GitHub Stars

15

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Reviews

Top Feedback

1Abandoned

Readme

pagination-logic

Build Status npm version

Pure Javascript pagination logic without UI component

Installation

npm install pagination-logic

Usage


var pagination = require('pagination-logic');

/*
Provide a pageObject
(total -- Number of items that will be paginated
 single -- Number of items per page
 pageSize -- Number of pageItem that will be shown
 currentPage -- Number of the page you want to get
 pageLinkRule -- a funtion you link to the page you want, param is pageNumber
)
*/
var paginationResult = pagination(pageObject)

Result Attributes

Name Description
pages A list about the elements showed in current page, each elements contains {number, link, isActive}
pageCount total page number
currentPage the currently active page
hasPrevious whether the current page has previous page
hasNext whether the current page has next page
pageSize Number of elements showing in the current page
previousPage the previous page object which contains {number, link, isActive}
nextPage the next page object which contains {number, link, isActive}
firstPage the first page object which contains {number, link, isEllipsis}. ps: isEllipsis means whether you need '......', like 1...5,6,7,8...100
lastPage the final page object which contains {number, link, isEllipsis}. ps: isEllipsis means whether you need '......', like 1...5,6,7,8...100

###Example

const test = require('ava');
const logicPaginate = require('../src/pagination-logic');


test('middle', function(t) {
    const input = {
        total: 50,
        single:6,
        pageSize:4,
        currentPage: 6,
        pageLinkRule: (pageNumber) => {
            return `/page/${pageNumber}`;
        }
    };
    const expectedOutput = {
           pages: [
                      {
                          number: 4,
                          link: '/page/4',
                          isActive: false,
                      },
                      {
                          number: 5,
                          link: '/page/5',
                          isActive: false,
                      },
                      {
                          number: 6,
                          link: '/page/6',
                          isActive: true,
                      },
                      {
                          number: 7,
                          link: '/page/7',
                          isActive: false,
                      }
                  ],
                  pageCount: 9,
                  currentPage: 6,
                  hasPrevious: true,
                  hasNext: true,
                  previousPage: {
                      number: 5,
                      link: '/page/5',
                      isActive: false,
                  },
                  nextPage: {
                      number: 7,
                      link: '/page/7',
                      isActive: false,
                  },
                  pageSize: 4,
                  firstPage:{
                      number:1,
                      link: '/page/1',
                      isEllipsis: true
                  },
                  lastPage:{
                      number:9,
                      link: '/page/9',
                      isEllipsis: true
                  },

       };
    t.deepEqual(logicPaginate(input), expectedOutput)
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned1
Unwelcoming Community0
100
Yeltsin LimaRecife, Brasil19 Ratings2 Reviews
9 months ago
Abandoned

Tutorials

No tutorials found
Add a tutorial