Skip to main content
cngx-src documentation

CngxPaginate

DirectivePrimaryv0.1.0WCAG AA

projects/common/data/paginate/paginate.directive.ts

Import#

import { CngxPaginate } from '@cngx/common/data'

Description#

Atom directive that tracks pagination state (current page index and page size).

Supports both uncontrolled (internal state) and controlled modes.
In controlled mode the cngxPageIndex / cngxPageSize inputs take precedence over internal state - pair with
pageChange / pageSizeChange to keep them in sync.

Consumer connects this to a list or table via range() - nothing is injected automatically.

// Headless: read range() from a template ref
<div cngxPaginate #pg="cngxPaginate" [total]="items.length">
  @for (item of items.slice(pg.range()[0], pg.range()[1]); track item.id) { ... }
</div>

// Drive any UI off the brain - e.g. a Material paginator wired by hand:
<mat-paginator
  [length]="pg.total()" [pageIndex]="pg.pageIndex()" [pageSize]="pg.pageSize()"
  (page)="pg.setPageSize($event.pageSize, false); pg.setPage($event.pageIndex)" />

https://cngxjs.github.io/cngx/examples/#/common/data/data-source/datasource-cngxpaginate-manual-pipeline https://cngxjs.github.io/cngx/examples/#/common/data/paginate-list/paginated-list-cngxpaginate-cngxmatpaginator https://cngxjs.github.io/cngx/examples/#/common/data/paginate-list/uncontrolled-mode-zero-class-boilerplate https://cngxjs.github.io/cngx/examples/#/common/data/smart-data-source/smartdatasource-cngxpaginate-hostdirective

Metadata#

Index#

Inputs#

pageIndexInput#number | undefined
input()

Controlled page index. When bound, takes precedence over internal state.

default undefined, { alias: 'cngxPageIndex' }
pageSizeInput#number | undefined
input()

Controlled page size. When bound, takes precedence over internal state.

default undefined, { alias: 'cngxPageSize' }

Bind an async state - disables navigation while the data source is busy. When set, isBusy derives from state.isBusy(). Navigation methods (setPage, next, previous, etc.) are no-ops while busy.

total#number
input()

Total number of items (before pagination). Consumer binds this from the filtered/sorted count so that totalPages stays accurate.

default 0

Outputs#

pageChange#number
output()

Emitted when the page index changes.

pageSizeChange#number
output()

Emitted when the page size changes.

Methods#

first#void

Navigate to the first page.

last#void

Navigate to the last page.

setPage#void
setPage(index: number)

Navigate to index, clamping to [0, totalPages - 1]. Emits pageChange.

@paramindexnumber
setPageSize#void
setPageSize(size: number, resetPage: unknown)

Change page size and optionally reset to page 0. Emits pageSizeChange and, when resetPage is true, pageChange.

@paramsizenumber
@paramresetPageunknown= true