{"id":13481570,"url":"https://github.com/michaelbromley/ngx-pagination","last_synced_at":"2026-01-11T17:58:08.055Z","repository":{"id":38839733,"uuid":"47828912","full_name":"michaelbromley/ngx-pagination","owner":"michaelbromley","description":"Pagination for Angular","archived":false,"fork":false,"pushed_at":"2022-11-21T15:30:14.000Z","size":15365,"stargazers_count":1235,"open_issues_count":50,"forks_count":244,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-04-11T18:24:22.936Z","etag":null,"topics":["angular","pagination"],"latest_commit_sha":null,"homepage":"http://michaelbromley.github.io/ngx-pagination/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelbromley.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-11T13:43:24.000Z","updated_at":"2025-04-05T10:39:45.000Z","dependencies_parsed_at":"2022-07-14T03:30:39.282Z","dependency_job_id":null,"html_url":"https://github.com/michaelbromley/ngx-pagination","commit_stats":null,"previous_names":["michaelbromley/ng2-pagination"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbromley%2Fngx-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbromley%2Fngx-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbromley%2Fngx-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbromley%2Fngx-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelbromley","download_url":"https://codeload.github.com/michaelbromley/ngx-pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254168143,"owners_count":22026098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","pagination"],"created_at":"2024-07-31T17:00:52.918Z","updated_at":"2026-01-11T17:58:08.011Z","avatar_url":"https://github.com/michaelbromley.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized","TypeScript","UI Components"],"sub_categories":["Uncategorized","Pagination"],"readme":"# Pagination for Angular [![Build Status](https://travis-ci.org/michaelbromley/ngx-pagination.svg?branch=master)](https://travis-ci.org/michaelbromley/ngx-pagination)\n\nThe simplest solution for pagination in Angular.\n\n## Table of Contents\n\n* [Demo](#demo)\n* [Quick Start](#quick-start)\n  + [Angular Version](#angular-version)\n* [Simple Example](#simple-example)\n* [API](#api)\n  + [PaginatePipe](#paginatepipe)\n  + [PaginationControlsComponent](#paginationcontrolscomponent)\n  + [PaginationControlsDirective](#paginationcontrolsdirective)\n* [Styling](#styling)\n* [Server-Side Paging](#server-side-paging)\n* [Multiple Instances](#multiple-instances)\n* [FAQ](#faq)\n  + [Why does my filter not work with pagination?](#why-does-my-filter-not-work-with-pagination)\n  + [How do I use the ngFor index with the pagination pipe?](#how-do-i-use-the-ngfor-index-with-the-pagination-pipe)\n  + [How do I get the absolute index of a list item?](#how-do-i-get-the-absolute-index-of-a-list-item)\n* [Building from source](#building-from-source)\n* [License](#license)\n\n\n## Demo\n\nCheck out the live demo here: http://michaelbromley.github.io/ngx-pagination/\n\nPlay with it on StackBlitz here: https://stackblitz.com/edit/angular-e1f9hq\n\n## Quick Start\n\n```\nnpm install ngx-pagination --save\n```\n\n### Angular Version\n\nThis library is built to work with **Angular 13+**.\nIf you need to support an earlier version of Angular, please use v5.x.\n\n## Simple Example\n\n```TypeScript\n// app.module.ts\nimport {NgModule} from '@angular/core';\nimport {BrowserModule} from '@angular/platform-browser';\nimport {NgxPaginationModule} from 'ngx-pagination'; // \u003c-- import the module\nimport {MyComponent} from './my.component';\n\n@NgModule({\n    imports: [BrowserModule, NgxPaginationModule], // \u003c-- include it in your app module\n    declarations: [MyComponent],\n    bootstrap: [MyComponent]\n})\nexport class MyAppModule {}\n```\n\n```TypeScript\n// my.component.ts\nimport {Component} from '@angular/core';\n\n@Component({\n    selector: 'my-component',\n    template: `\n    \u003cul\u003e\n      \u003cli *ngFor=\"let item of collection | paginate: { itemsPerPage: 10, currentPage: p }\"\u003e ... \u003c/li\u003e\n    \u003c/ul\u003e\n               \n    \u003cpagination-controls (pageChange)=\"p = $event\"\u003e\u003c/pagination-controls\u003e\n    `\n})\nexport class MyComponent {\n    p: number = 1;\n    collection: any[] = someArrayOfThings;  \n}\n```\n\n## API\n\n### PaginatePipe\n\nThe PaginatePipe should be placed at the end of an NgFor expression. It accepts a single argument, an object conforming \nto the [`PaginationInstance` interface](/projects/ngx-pagination/src/lib/pagination-instance.ts). The following config options are available:\n\n```HTML\n\u003csome-element *ngFor=\"let item of collection | paginate: { id: 'foo',\n                                                      itemsPerPage: pageSize,\n                                                      currentPage: p,\n                                                      totalItems: total }\"\u003e...\u003c/some-element\u003e\n\n```\n\n* **`itemsPerPage`** [`number`] - **required** The number of items to display on each page.\n* **`currentPage`** [`number`] - **required** The current (active) page number.\n* **`id`** [`string`] If you need to support more than one instance of pagination at a time, set the `id` and ensure it\nmatches the id attribute of the `PaginationControlsComponent` / `PaginationControlsDirective` (see below).\n* **`totalItems`** [`number`] The total number of items in the collection. Only useful when doing server-side paging, \nwhere the collection size is limited to a single page returned by the server API. For in-memory paging, \nthis property should not be set, as it will be automatically set to the value of `collection.length`.\n\n### PaginationControlsComponent\n\nThis a default component for displaying pagination controls. It is implemented on top of the `PaginationControlsDirective`, and has a pre-set\ntemplate and styles based on the [Foundation 6 pagination component](http://foundation.zurb.com/sites/docs/pagination.html). If you require a more \ncustomised set of controls, you will need to use the `PaginationControlsDirective` and implement your own component.\n\n```HTML\n\u003cpagination-controls  id=\"some_id\"\n                      (pageChange)=\"pageChanged($event)\"\n                      (pageBoundsCorrection)=\"pageChanged($event)\"\n                      maxSize=\"9\"\n                      directionLinks=\"true\"\n                      autoHide=\"true\"\n                      responsive=\"true\"\n                      previousLabel=\"Previous\"\n                      nextLabel=\"Next\"\n                      screenReaderPaginationLabel=\"Pagination\"\n                      screenReaderPageLabel=\"page\"\n                      screenReaderCurrentLabel=\"You're on page\"\u003e\n\u003c/pagination-controls\u003e\n```\n\n* **`id`** [`string`] If you need to support more than one instance of pagination at a time, set the `id` and ensure it\nmatches the id set in the PaginatePipe config.\n* **`pageChange`** [`event handler`] The expression specified will be invoked whenever the page changes via a click on one of the\npagination controls. The `$event` argument will be the number of the new page. This should be used to update the value of the `currentPage` variable which was passed to the `PaginatePipe`.\n* **`pageBoundsCorrection`** [`event handler`] The expression specified will be invoked when the `currentPage` value is found to be out-of-bounds (e.g. the collection size was reduced). The `$event` argument will be the number of the closest valid page.\n* **`maxSize`** [`number`] Defines the maximum number of page links to display. Default is `7`. Minimum is `5`.\n* **`directionLinks`** [`boolean`] If set to `false`, the \"previous\" and \"next\" links will not be displayed. Default is `true`.\n* **`autoHide`** [`boolean`] If set to `true`, the pagination controls will not be displayed when all items in the\ncollection fit onto the first page. Default is `false`.\n* **`responsive`** [`boolean`] If set to `true`, individual page links will not be displayed on small screens. Default is `false`.\n* **`previousLabel`** [`string`] The label displayed on the \"previous\" link.\n* **`nextLabel`** [`string`] The label displayed on the \"next\" link.\n* **`screenReaderPaginationLabel`** [`string`] The word for \"Pagination\" used to label the controls for screen readers.\n* **`screenReaderPageLabel`** [`string`] The word for \"page\" used in certain strings generated for screen readers, e.g. \"Next page\".\n* **`screenReaderCurrentLabel`** [`string`] The phrase indicating the current page for screen readers, e.g. \"You're on page \u003cx\u003e\".\n\n### PaginationControlsDirective\n\nThe `PaginationControlsDirective` is used to build components for controlling your pagination instances. The directive selector is `pagination-template`, either as an element or an attribute. \nIt exports an API named \"paginationApi\", which can then be used to build the controls component.\n\nIt has the following inputs and outputs:\n\n```TypeScript\n@Input() id: string;\n@Input() maxSize: number;\n@Output() pageChange: EventEmitter\u003cnumber\u003e;\n@Output() pageBoundsCorrection: EventEmitter\u003cnumber\u003e;\n```\n\nHere is an example of how it would be used to build a custom component:\n\n```HTML\n\u003cpagination-template #p=\"paginationApi\"\n                     (pageChange)=\"pageChange.emit($event)\"\n                     (pageBoundsCorrection)=\"pageBoundsCorrection.emit($event)\"\u003e\n\n        \u003cdiv class=\"pagination-previous\" [class.disabled]=\"p.isFirstPage()\"\u003e\n            \u003ca *ngIf=\"!p.isFirstPage()\" (click)=\"p.previous()\"\u003e \u003c \u003c/a\u003e\n        \u003c/div\u003e\n\n        \u003cdiv *ngFor=\"let page of p.pages\" [class.current]=\"p.getCurrent() === page.value\"\u003e\n            \u003ca (click)=\"p.setCurrent(page.value)\" *ngIf=\"p.getCurrent() !== page.value\"\u003e\n                \u003cspan\u003e{{ page.label }}\u003c/span\u003e\n            \u003c/a\u003e\n            \u003cdiv *ngIf=\"p.getCurrent() === page.value\"\u003e\n                \u003cspan\u003e{{ page.label }}\u003c/span\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n\n        \u003cdiv class=\"pagination-next\" [class.disabled]=\"p.isLastPage()\"\u003e\n            \u003ca *ngIf=\"!p.isLastPage()\" (click)=\"p.next()\"\u003e \u003e \u003c/a\u003e\n        \u003c/div\u003e\n    \n\u003c/pagination-template\u003e\n```\n\nThe key thing to note here is `#p=\"paginationApi\"` - this provides a local variable, `p` (name it however you like), which can be used in the \ntemplate to access the directive's API methods and properties, which are explained below:\n\n* **`pages`** [`{ label: string, value: any }[]`] Array of page objects containing the page number and label.\n* **`maxSize`** [`number`]  Corresponds to the value of `maxSize` which is passed to the directive.\n* **`getCurrent()`** [`() =\u003e number`] Returns the current page number.\n* **`setCurrent(val)`** [`(val: number) =\u003e void`] Triggers the `pageChange` event with the page number passed as `val`.\n* **`previous()`** [`() =\u003e void`] Sets current page to previous, triggering the `pageChange` event.\n* **`next()`** [`() =\u003e void`] Sets current page to next, triggering the `pageChange` event.\n* **`isFirstPage()`** [`() =\u003e boolean`] Returns true if the current page is the first page.\n* **`isLastPage()`** [`() =\u003e boolean`] Returns true if the current page is the last page\n* **`getLastPage()`** [`() =\u003e number`] Returns the page number of the last page.\n* **`getTotalItems()`** [`() =\u003e number`] Returns the total number of items in the collection.\n\nFor a real-world implementation of a custom component, take a look at [the source for the PaginationControlsComponent](/projects/ngx-pagination/src/lib/pagination-controls.component.ts).\n\n## Styling\n\nThe `PaginationControlsComponent` can be styled by simply overriding the default styles. To overcome Angular's view encapsulation, you may need to use the `::ng-deep` operator to target it (depending on the type of encapsulation your component is using).\n\nTo avoid specificity issues, just add your own custom class name to the element, which will allow your styles to override the defaults:\n\n```HTML\n// head\n\u003cstyle\u003e\n  .my-pagination ::ng-deep .ngx-pagination .current {\n    background: red;\n  }\n\u003c/style\u003e\n\n// body\n\u003cpagination-controls class=\"my-pagination\"\u003e\u003cpagination-controls\u003e\n```\n\n## Server-Side Paging\n\nIn many cases - for example when working with very large data-sets - we do not want to work with the full collection \nin memory, and use some kind of server-side paging, where the server sends just a single page at a time.\n\nThis scenario is supported by ngx-pagination by using the `totalItems` config option. \n\nGiven a server response json object like this:\n\n```\n{\n  \"count\": 14453,\n  \"data\": [\n    { /* item 1 */ },\n    { /* item 2 */ },\n    { /* item 3 */ },\n    { /*   ...  */ },\n    { /* item 10 */ }\n  ]\n}\n```\n\nwe should pass the value of `count` to the `PaginatePipe` as the `totalItems` argument:\n\n```HTML\n\u003cli *ngFor=\"let item of collection | paginate: { itemsPerPage: 10, currentPage: p, totalItems: res.count }\"\u003e...\u003c/li\u003e\n```\n\nThis will allow the correct number of page links to be calculated. To see a complete example of this (including\nusing the `async` pipe), see the [demo](http://michaelbromley.github.io/ngx-pagination/).\n\n## Multiple Instances\n\nIt is possible to have any number of pagination pipe/controls pairs in the same template. To do this, just make use of the \"id\" attribute:\n\n```HTML\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | paginate: { itemsPerPage: 10, currentPage: p1, id: 'first' }\"\u003e ... \u003c/li\u003e\n\u003c/ul\u003e\n\u003cpagination-controls (pageChange)=\"p1 = $event\" id=\"first\"\u003e\u003c/pagination-controls\u003e\n\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | paginate: { itemsPerPage: 10, currentPage: p2, id: 'second' }\"\u003e ... \u003c/li\u003e\n\u003c/ul\u003e\n\u003cpagination-controls (pageChange)=\"p2 = $event\" id=\"second\"\u003e\u003c/pagination-controls\u003e\n```\n\nYou can even have dynamically-generated instances, e.g. within an `ngFor` block:\n\n```TypeScript\nexport class MyComponent {\n  p: number[] = [];\n}\n```\n\n```HTML\n\u003cdiv *ngFor=\"let id of [1, 2]; let i = index;\"\u003e\n  \u003cul\u003e\n    \u003cli *ngFor=\"let item of collection | paginate: { itemsPerPage: 10, currentPage: p[i], id: id }\"\u003e{{ item }}\u003c/li\u003e\n   \u003c/ul\u003e\n   \u003cpagination-controls (pageChange)=\"p[i] = $event\" [id]=\"id\"\u003e\u003c/pagination-controls\u003e\n\u003c/div\u003e\n```\n\n## FAQ\n\n### Why does my filter not work with pagination?\n\nA common issue is that people have trouble combining some kind of filter pipe with the paginate pipe. The typical symptom is that only the contents of the current page are filtered. The reason is that **the paginate pipe must come after the filter pipe**:\n\n```HTML\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | paginate: config | filter: queryString\"\u003eWRONG\u003c/li\u003e \u003c-- This will not work as expected\n\u003c/ul\u003e\n\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | filter: queryString | paginate: config\"\u003eCORRECT\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n### How do I use the ngFor index with the pagination pipe?\n\nIf you need to use the index of the `*ngFor` in combination with pagination pipe, **the index should be declared after the pagination pipe**:\n\n```HTML\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection; let i = index | paginate: config\"\u003eWRONG\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | paginate: config; let i = index\"\u003eCORRECT\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n### How do I get the absolute index of a list item?\n\nUsing the `index` variable exposed by `ngFor` will always give you the index of the items relative to the current page. For example, if you have 10 items per page, you might expect the first item on page 2 to have an index value of 10, whereas you will find the index value to be 0. This is because `ngFor` has no knowledge of the pagination, it only ever knows about the 10 items of the current page.\n\nHowever, the absolute index can be calculated according to the following formula:\n\n```TypeScript\nabsoluteIndex(indexOnPage: number): number {\n  return this.itemsPerPage * (this.currentPage - 1) + indexOnPage;\n}\n```\nIn a template this would look something like:\n```HTML\n\u003cul\u003e\n  \u003cli *ngFor=\"let item of collection | paginate: { currentPage: currentPage, itemsPerPage: itemsPerPage }; let i = index\"\u003e\n    {{ itemsPerPage * (currentPage - 1) + i }}\n  \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n## Building from source\n\nRequires globally-installed node (tested with v5.x) \u0026 npm. \n\n```\nnpm install\nnpm run test\nnpm run build \n```\n\nAfter running `npm run build`, the final output of the lib (which gets published to npm) is in the `/dist/ngx-pagination` folder.\n\nTo build the docs, run `npm run build:docs`, or serve them in dev mode with `npm run start`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelbromley%2Fngx-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelbromley%2Fngx-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelbromley%2Fngx-pagination/lists"}