All Projects → prototype-berlin → loopback-paginator

prototype-berlin / loopback-paginator

Licence: MIT License
No description or website provided.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to loopback-paginator

loopback-ds-paginate-mixin
A mixin to provide pagination for loopback Model properties
Stars: ✭ 31 (+138.46%)
Mutual labels:  loopback, loopback-mixin
loopback-row-count-mixin
A loopback mixin to get total count of a model
Stars: ✭ 13 (+0%)
Mutual labels:  pagination, loopback-mixin
loopback-object-acl
Object-level ACL for Loopback Node.js framework
Stars: ✭ 13 (+0%)
Mutual labels:  loopback, loopback-mixin
dynamodb-paginator
Paginate DynamoDB results easily
Stars: ✭ 18 (+38.46%)
Mutual labels:  pagination
loopback-component-migrate
Migration framework for loopback
Stars: ✭ 43 (+230.77%)
Mutual labels:  loopback
TableBundle
Symfony Bundle for easy pagination and filtering
Stars: ✭ 24 (+84.62%)
Mutual labels:  pagination
n-odata-server
Node.js OData Server
Stars: ✭ 79 (+507.69%)
Mutual labels:  loopback
fire-starter
Starter kit for the fireloop.io platform
Stars: ✭ 16 (+23.08%)
Mutual labels:  loopback
Exopite-Multifilter-Multi-Sorter-WordPress-Plugin
Display and/or sort/filter any page or post types by multiple taxonomies or terms (like post by categories and/or tags) with AJAX. Exopite multifilter, multi-sortable, multi selectable, multi filterable sortable Wordpress Plugin.
Stars: ✭ 18 (+38.46%)
Mutual labels:  pagination
f3-pagination
A pagebrowser and some pagination utilities for the PHP Fat-Free Framework
Stars: ✭ 15 (+15.38%)
Mutual labels:  pagination
django-simple-pagination
django pagination as you want it to be
Stars: ✭ 41 (+215.38%)
Mutual labels:  pagination
v-page
A simple pagination bar, including length Menu, i18n support, based on Vue2.x
Stars: ✭ 85 (+553.85%)
Mutual labels:  pagination
easy-css-layout
Easy css layout
Stars: ✭ 117 (+800%)
Mutual labels:  pagination
react-hot-pagination
A React component to render your pagination navigation
Stars: ✭ 28 (+115.38%)
Mutual labels:  pagination
flop
Filtering, ordering and pagination for Ecto
Stars: ✭ 56 (+330.77%)
Mutual labels:  pagination
cakephp-api-pagination
📑 CakePHP 4 plugin that injects pagination information into API responses.
Stars: ✭ 39 (+200%)
Mutual labels:  pagination
docsify-pagination
↔️ Pagination for docsify
Stars: ✭ 80 (+515.38%)
Mutual labels:  pagination
spring-thymeleaf-pagination
Spring Boot application which demonstrates implementation of pagination in Java web application with Thymeleaf template engine
Stars: ✭ 73 (+461.54%)
Mutual labels:  pagination
Pagination-Utils
A collection of methods to make message pagination with JDA easier.
Stars: ✭ 20 (+53.85%)
Mutual labels:  pagination
lightning-data-table
Lightning components for building a data-table with search, column sorting, pagination for Salesforce
Stars: ✭ 15 (+15.38%)
Mutual labels:  pagination

Pagination mixin for LoopBack

Paginator adds an easy to use pagination to any of your models. See the example below.

Installation

$ npm i loopback-paginator --save

Demo application

A woring demo application is available here.

Config

Server Config

With [email protected] mixinSources have been implemented in a way which allows for loading this mixin without changes to the server.js file previously required. Just add "../node_modules/loopback-paginator" to the mixins property of your server/model-config.json.

{
  "_meta": {
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-paginator",
      "../common/mixins"
    ]
  }
}

Model Config

To use with your models just add Paginator: true to mixins in your model config and the default options will be used:

{
  "name": "Model",
  "properties": {
    "name": {
      "type": "string",
    }
  },
  "mixins": {
    "Paginator": true
  }

  ...

  // you can also overide the default values:
  "mixins": {
    "Paginator": {
      "limit": 5,         // items per page, default: 10
      "maxLimit": 60,     // max items per page, default: 100
      "noMaxLimit": true  // only use this, if you know what you are doing!
    }
  }
}

limit and maxLimit

  • limit is the default limit to be used for this model
  • maxLimit is the default maximum number of items per page for this model. As you can override the default limit using the LoopBack limit filter it might come in handy to set a maxLimit to prevent your API from being abused. The default is 100.
  • noMaxLimit set to true will deactivate the maxLimit. Be careful!

Global Config

It is also possible to configure the mixin globally in your config.json. Just add paginator and use the same options as with the model above:

{
  "paginator": {
    "limit": 20,       // items per page, default: 10
    "maxLimit": 300,   // max items per page, default: 100
    "noMaxLimit": true // only use this, if you know what you are doing!
  }
}

limit and maxLimit

  • limit is the default limit to be used globally
  • maxLimit is the default maximum number of items per page globally. As you can override the default limit using the LoopBack limit filter it might come in handy to set a maxLimit to prevent your API from being abused. The global default is 100.
  • noMaxLimit set to true will deactivate the maxLimit. Be careful!

Usage

When Paginator is added to a model and the page query parameter is present (e.g. ?page=1), Model.find() will return an object with data and meta. data is an array with the queried items, limited to the number you defined in the mixin options (see Model Config). meta contains information about the requested page (see example below). You can specify the page as a query parameter (e.g. ?page=3). If no page is specified it defaults to 1 (deprecated in versions >= 2.0.0).

/GET https://example.com/api/items?page=3

{
  "data": [
    {
      "title": "Item 1",
      "description": "Cool first item.",
      "id": "c5075168-abe0-41c6-8052-e07745eade48"
    },
    {
      "title": "Item 2",
      "description": "Cool second item.",
      "id": "0cad55df-c59d-4195-bb4f-7a252bd4bbe8",
    }

    ...

  ],
  "meta": {
    "totalItemCount": 95, // total number of items
    "totalPageCount": 10, // total number of all pages
    "itemsPerPage": 10,   // numberof items per page
    "currentPage": 3,     // the current page
    "nextPage": 4,        // the next page, only present if there is another page
    "previousPage": 2     // the previous page, only present if currentPage != 1
  }
}

ToDo

  • allow to override limit with an URL parameter

License

MIT

Changelog

v3.0.0

  • Breaking change: Add the mixin in server/model-config.json like this: "../node_modules/loopback-paginator", without the former /lib at the end
  • Remove Babel dependencies

v2.0.0

  • Breaking change: node >=8.0.0 is required!
  • Breaking change: omitting the page parameter no longer defaults to page=1, it now returns unpaginated results

v1.0.0

  • Allow to override limit with the LoopBack limit filter
  • Add maxLimit option
  • Add noMaxLimit option

v0.9.6

  • Add global config
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].