think-pagination

2.0.1 • Public • Published

think-pagination

pagination for ThinkJS 3, if you want to use in ThinkJS 2.x, please view README_v2

install

npm install think-pagination

how to use

controller

const pagination = require('think-pagination');

module.exports = class extends think.Controller {
  async indexAction() {
    const data = await this.model('user').page(this.get('page')).countSelect();
    const html = pagination(data, this.ctx, {});
    this.assign('pagination', html);
  }
}

view

ejs

{%-pagination%}

nunjucks

{{pagination | safe}}

API

pagination(pagerData, ctx, options)

  • pagerData get from by model.countSelect
  • ctx ctx object
  • options options

options:

{
  desc: false, //show description
  pageNum: 2, 
  url: '', //page url, when not set, it will auto generated
  class: '', //pagenation extra class
  text: {
    next: 'Next',
    prev: 'Prev',
    total: 'count: __COUNT__ , pages: __PAGE__'
  }
}

/think-pagination/

    Package Sidebar

    Install

    npm i think-pagination

    Weekly Downloads

    5

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    8.04 kB

    Total Files

    7

    Last publish

    Collaborators

    • lizheming
    • welefen
    • sijiecai
    • lushijie
    • berwin
    • bezos
    • toxicjohann
    • huangxiaolu