PaginatorPaginator is a generic widget to display content in paged format.

Paginator - 图1

Documentation

Import

  1. import {PaginatorModule} from 'primeng/paginator';
  2.  

Getting Started

Paginator is defined using p-paginator element.

  1. <p-paginator></p-paginator>
  2.  

Rows and TotalRecords

Rows and TotalRecords define how many pages the paginator should display. Paginator below will have 10 pages.

  1. <p-paginator [rows]="10" [totalRecords]="100"></p-paginator>
  2.  

PageLinks provide shortcuts to jump to a specific page, use pageLinkSize property to define the number of links to display. Default is 5.

  1. <p-paginator [rows]="10" [totalRecords]="100" pageLinkSize="3"></p-paginator>
  2.  

Rows Per Page

Number of items per page can be changed by the user using a dropdown if you define rowsPerPageOptions as an array of possible values.

  1. <p-paginator [rows]="10" [totalRecords]="120" [rowsPerPageOptions]="[10,20,30]"></p-paginator>
  2.  

Properties

NameTypeDefaultDescription
totalRecordsnumber0Number of total records.
rowsnumber0Data count to display per page.
firstnumber0Zero-relative number of the first row to be displayed.
pageLinkSizenumber5Number of page links to display.
rowsPerPageOptionsarraynullArray of integer values to display inside rows per page dropdown.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
alwaysShowbooleantrueWhether to show it even there is only one page.
templateLeftTemplateRefnullTemplate instance to inject into the left side of the paginator.
templateRightTemplateRefnullTemplate instance to inject into the right side of the paginator.
dropdownAppendToanynullTarget element to attach the dropdown overlay, valid values are "body" or a local ng-template variable of another element.
currentPageReportTemplatestring{currentPage} of {totalPages}Text to display the current page information.
showCurrentPageReportbooleanfalseWhether to display current page report.

Events

NameParametersDescription
onPageChangeevent.first: Index of first record event.rows: Number of rows to display in new page event.page: Index of the new page event.pageCount: Total number of pages Callback to invoke when page changes, the event object contains information about the new state.
  1. <p-paginator [rows]="10" totalRecords="100" (onPageChange)="paginate($event)"></p-paginator>
  2.  
  1. export class MyComponent {
  2. paginate(event) {
  3. //event.first = Index of the first record
  4. //event.rows = Number of rows to display in new page
  5. //event.page = Index of the new page
  6. //event.pageCount = Total number of pages
  7. }
  8. }
  9.  

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-paginatorContainer element.
ui-paginator-firstFirst page element.
ui-paginator-prevPrevious page element.
ui-paginator-pagesContainer of page links.
ui-paginator-pageA page link.
ui-paginator-nextNext page element.
ui-paginator-lastLast page element.
ui-paginator-rpp-optionsRows per page dropdown.

Dependencies

None.

Source

View on GitHub

  1. <p-paginator [rows]="10" [totalRecords]="120" [rowsPerPageOptions]="[10,20,30]"></p-paginator>
  2.