Class

PaginationComponent

PaginationComponent()

Constructor

# new PaginationComponent()

This component provides a user interface for paginated content navigation, displaying page numbers and navigation controls. It supports customizable page counts, current page tracking, and emits events when users navigate between pages.

The component intelligently handles large numbers of pages by showing a subset of page numbers with ellipses to indicate skipped pages, ensuring the UI remains clean and usable even with many pages.

A pagination component for navigating through multiple pages of content.

sequenceDiagram participant U as User participant P as PaginationComponent participant E as External Component U->>P: Click page number P->>P: navigate(page) P->>P: handleClick(direction, page) P->>E: Emit clickEvent with PaginationCustomEvent U->>P: Click next button P->>P: next() P->>P: handleClick('next') P->>E: Emit clickEvent with PaginationCustomEvent U->>P: Click previous button P->>P: previous() P->>P: handleClick('previous') P->>E: Emit clickEvent with PaginationCustomEvent
Implements:
  • OnInit

View Source lib/components/pagination/pagination.component.ts, line 56

Example
<ngx-decaf-pagination
  [pages]="10"
  [current]="3"
  (clickEvent)="handlePageChange($event)">
</ngx-decaf-pagination>

Extends

Classes

NgxBaseComponent

Initializes a new instance of the base component with the provided instance token. This constructor sets up the fundamental properties required by all Decaf components, including the component name, locale settings, and logging capabilities. The instance token is used for component identification and locale derivation.

The constructor performs the following initialization steps:

  1. Sets the componentName from the provided instance token
  2. Derives the componentLocale from the class name using utility functions
  3. Initializes the logger instance for the component
PaginationComponent
Initializes a new instance of the PaginationComponent.

Members

DecafRepository.<Model>

# protected _repository

Provides a connection to the data layer for retrieving and manipulating data. This is an instance of the DecafRepository class from the @decaf-ts/core package, which is initialized in the repository getter method.

The repository is used to perform CRUD (Create, Read, Update, Delete) operations on the data model, such as fetching data, creating new items, updating existing items, and deleting items. It also provides methods for querying and filtering data based on specific criteria.

The repository for interacting with the data model.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 779

string

# className

Allows custom CSS classes to be added to the component's root element. These classes are appended to any automatically generated classes based on other component properties. Multiple classes can be provided as a space-separated string. This provides a way to customize the component's appearance beyond the built-in styling options.

Additional CSS class names to apply to the component.

Overrides:
Default Value:
  • ""

View Source lib/engine/NgxBaseComponent.ts, line 897

EventEmitter.<PaginationCustomEvent>

# clickEvent

Emits a custom event when users navigate between pages, either by clicking on page numbers or using the next/previous buttons. The event contains information about the navigation direction and the target page number.

Event emitter for pagination navigation events.

View Source lib/components/pagination/pagination.component.ts, line 431

ElementRef

# component

Provides direct access to the native DOM element of the component through Angular's ViewChild decorator. This reference can be used to manipulate the DOM element directly, apply custom styles, or access native element properties and methods. The element is identified by the 'component' template reference variable.

Reference to the component's element.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 721

string

# componentLocale

Stores the automatically derived locale based on the component's class name. This is determined during component initialization and serves as a fallback when no explicit locale is provided via the locale input property. The derivation is handled by the getLocaleFromClassName utility function, which extracts a locale identifier from the component's class name.

The locale derived from the component's class name.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 924

string

# protected componentName

Stores the name of the component, which is typically derived from the class name. This property is used internally for various purposes such as logging, deriving the default locale, and potentially for component identification in debugging or error reporting.

The componentName is set during the component's initialization process and should not be modified externally. It's marked as protected to allow access in derived classes while preventing direct access from outside the component hierarchy.

The name of the component.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 741

Example
// Inside a derived component class
console.log(this.componentName); // Outputs: "MyCustomComponent"
number

# current

Specifies which page is currently active or selected. This value is used to highlight the current page in the UI and as a reference point for navigation.

The currently active page number.

Default Value:
  • 1

View Source lib/components/pagination/pagination.component.ts, line 401

boolean

# initialized

Tracks whether the component has completed its initialization process. This flag is used to prevent duplicate initialization and to determine if certain operations that require initialization can be performed.

Flag indicating if the component has been initialized

Overrides:
Default Value:
  • false

View Source lib/engine/NgxBaseComponent.ts, line 303

Record.<string, unknown>

# item

Defines how list items should be rendered in the component. This property holds a configuration object that specifies the tag name and other properties needed to render list items correctly. The tag property identifies which component should be used to render each item in a list. Additional properties can be included to customize the rendering behavior.

Configuration for list item rendering

Overrides:
Default Value:
  • {tag: ""}

View Source lib/engine/NgxBaseComponent.ts, line 807

number

# last

Stores the number of the last page for boundary checking during navigation.

The last page number in the pagination.

View Source lib/components/pagination/pagination.component.ts, line 420

EventEmitter.<RendererCustomEvent>

# listenEvent

Emits custom events that occur within child components or the layout itself. This allows parent components to listen for and respond to user interactions or state changes within the grid layout. Events are passed up the component hierarchy to enable coordinated behavior across the application.

Event emitter for custom renderer events.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 960

string

# locale

Specifies the locale identifier to use when translating component text. This can be set explicitly via input property to override the automatically derived locale from the component name. The locale is typically a language code (e.g., 'en', 'fr') or a language-region code (e.g., 'en-US', 'fr-CA') that determines which translation set to use for the component's text content.

The locale to be used for translations.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 871

Record.<string, string>

# mapper

Defines how fields from the data model should be mapped to properties used by the component. This allows for flexible data binding between the model and the component's display logic.

Field mapping configuration.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 858

"ios" | "md" | undefined

# mode

Controls the visual appearance of the component based on platform design guidelines. The 'ios' mode follows iOS design patterns, while 'md' (Material Design) follows Android/Google design patterns. This property affects various visual aspects such as animations, form elements, and icons. Setting this property allows components to maintain platform-specific styling for a more native look and feel.

Component platform style.

Overrides:
Default Value:
  • "md"

View Source lib/engine/NgxBaseComponent.ts, line 911

Model | undefined

# model

The data model repository that this component will use for CRUD operations. This provides a connection to the data layer for retrieving and manipulating data.

Repository model for data operations.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 762

Array

# operations

Defines which CRUD operations (Create, Read, Update, Delete) are available for this component. This affects which operations can be performed on the data.

Available CRUD operations for this component.

Overrides:
Default Value:
  • [OperationKeys.READ]

View Source lib/engine/NgxBaseComponent.ts, line 838

Array.<KeyValue>

# pages

Contains the processed page data used for rendering the pagination UI. Each object includes an index (page number) and text representation.

Array of page objects for rendering in the template.

View Source lib/components/pagination/pagination.component.ts, line 411

string

# pk

Specifies which field in the model should be used as the primary key. This is typically used for identifying unique records in operations like update and delete.

Primary key field name for the model.

Overrides:
Default Value:
  • 'id'

View Source lib/engine/NgxBaseComponent.ts, line 818

Record.<string, unknown>

# props

Contains key-value pairs of dynamic properties that can be applied to the component at runtime. This flexible configuration object allows for dynamic property assignment without requiring explicit input bindings for every possible configuration option. Properties from this object are parsed and applied to the component instance through the parseProps method, enabling customizable component behavior based on external configuration.

Dynamic properties configuration object.

Overrides:
Default Value:
  • {}

View Source lib/engine/NgxBaseComponent.ts, line 793

string | StringOrBoolean

# renderChild

Determines if child components should be rendered by the component. This can be set to a boolean value or a string that can be converted to a boolean. When true, child components defined in the model will be rendered. When false, child components will be skipped. This provides control over the rendering depth.

Controls whether child components should be rendered

Overrides:
Default Value:
  • true

View Source lib/engine/NgxBaseComponent.ts, line 937

string

# rendererId

A unique identifier used to reference the component's renderer instance. This can be used for targeting specific renderer instances when multiple components are present on the same page.

Unique identifier for the renderer.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 752

NgxRenderingEngine

# renderingEngine

Provides access to the NgxRenderingEngine singleton instance, which handles the rendering of components based on model definitions. This engine is used to extract decorator metadata and render child components.

Reference to the rendering engine instance

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 323

string

# route

Defines the base route path used for navigation actions related to this component. This is often used as a prefix for constructing navigation URLs.

Base route for navigation related to this component.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 828

number

# totalPages

Specifies the total number of pages available for navigation. This is a required input that determines how many page numbers will be generated and displayed.

The total number of pages to display in the pagination component.

View Source lib/components/pagination/pagination.component.ts, line 391

StringOrBoolean

# translatable

When set to true, the component will attempt to use translation services for any text content. This allows for internationalization of the pagination component.

Controls whether the component uses translation services.

Overrides:
Default Value:
  • true

View Source lib/components/pagination/pagination.component.ts, line 380

string | number

# uid

A unique identifier for the current record being displayed or manipulated. This is typically used in conjunction with the primary key for operations on specific records.

Unique identifier for the current record.

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 848

Paginator.<Model>

# static ListComponent#paginator

Provides a paginator object that can be used to retrieve and navigate through data in chunks, reducing memory usage and improving performance.

The paginator object is initialized in the ngOnInit lifecycle hook and is used to fetch and display data in the pagination component. It is an instance of the Paginator class from the @decaf-ts/core package, which provides methods for querying and manipulating paginated data.

A paginator object for handling pagination operations.

View Source lib/components/list/list.component.ts, line 1692

EventEmitter.<PaginationCustomEvent>

# static clickEvent

Emits a custom event when users navigate between pages, either by clicking on page numbers or using the next/previous buttons. The event contains information about the navigation direction and the target page number.

Event emitter for pagination navigation events.

View Source lib/components/pagination/pagination.component.ts, line 113

number

# static current

Specifies which page is currently active or selected. This value is used to highlight the current page in the UI and as a reference point for navigation.

The currently active page number.

Default Value:
  • 1

View Source lib/components/pagination/pagination.component.ts, line 86

number

# static last

Stores the number of the last page for boundary checking during navigation.

The last page number in the pagination.

View Source lib/components/pagination/pagination.component.ts, line 103

Array.<KeyValue>

# static pages

Contains the processed page data used for rendering the pagination UI. Each object includes an index (page number) and text representation.

Array of page objects for rendering in the template.

View Source lib/components/pagination/pagination.component.ts, line 95

Paginator.<Model>

# static paginator

Provides a paginator object that can be used to retrieve and navigate through data in chunks, reducing memory usage and improving performance.

The paginator object is initialized in the ngOnInit lifecycle hook and is used to fetch and display data in the pagination component. It is an instance of the Paginator class from the @decaf-ts/core package, which provides methods for querying and manipulating paginated data.

A paginator object for handling pagination operations.

View Source lib/components/list/list.component.ts, line 410

number

# static totalPages

Specifies the total number of pages available for navigation. This is a required input that determines how many page numbers will be generated and displayed.

The total number of pages to display in the pagination component.

View Source lib/components/pagination/pagination.component.ts, line 76

StringOrBoolean

# static translatable

When set to true, the component will attempt to use translation services for any text content. This allows for internationalization of the pagination component.

Controls whether the component uses translation services.

Default Value:
  • true

View Source lib/components/pagination/pagination.component.ts, line 66

Methods

# getCurrent() → {number}

Returns the current page number that is active in the pagination component. This method provides a way to access the current page state from outside the component.

Gets the current active page number.

View Source lib/components/pagination/pagination.component.ts, line 524

The current page number

number

# getLocale(translatable) → {string}

Determines which locale string to use for translation based on the translatable flag and available locale settings. This method first converts the translatable parameter to a boolean using the stringToBoolean utility function. If translatable is false, it returns an empty string, indicating no translation should be performed. If translatable is true, it checks for an explicitly provided locale via the locale property. If no explicit locale is available, it falls back to the componentLocale derived from the component's class name.

Gets the appropriate locale string based on the translatable flag and available locales.

sequenceDiagram participant C as Component participant N as NgxBaseComponent participant S as StringUtils C->>N: getLocale(translatable) N->>S: stringToBoolean(translatable) S-->>N: Return boolean value N->>N: Store in this.translatable alt translatable is false N-->>C: Return empty string else translatable is true alt this.locale is defined N-->>C: Return this.locale else this.locale is not defined N-->>C: Return this.componentLocale end end
Parameters:
Name Type Description
translatable StringOrBoolean

Whether the component should be translated

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 518

The locale string to use for translation, or empty string if not translatable

string

# getModel(model) → {void}

Processes the provided model parameter, which can be either a Model instance or a string identifier. If a string is provided, it attempts to resolve the actual model from the injectables registry. After resolving the model, it calls setModelDefinitions to configure the component based on the model's metadata.

Resolves and sets the component's model

Parameters:
Name Type Description
model string | Model

The model instance or identifier string

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 550

void

# getPages(total, currentopt) → {Array.<KeyValue>}

Creates an array of page objects based on the total number of pages and the current page. For small page counts (≤5), all pages are shown. For larger page counts, a subset is shown with ellipses to indicate skipped pages. This ensures the pagination UI remains clean and usable even with many pages.

Generates the array of page objects for display.

flowchart TD A[Start] --> B{total <= 5?} B -->|Yes| C[Show all pages] B -->|No| D[Show first page] D --> E[Show last pages] E --> F[Add ellipses for skipped pages] C --> G[Return pages array] F --> G
Parameters:
Name Type Attributes Description
total number

The total number of pages

current number <optional>

The current active page (defaults to this.current)

View Source lib/components/pagination/pagination.component.ts, line 514

Array of page objects with index and text properties

Array.<KeyValue>

# getRoute() → {string}

Retrieves the route path for the component, generating one based on the model if no route is explicitly set. This method checks if a route is already defined, and if not, it creates a default route based on the model's constructor name. The generated route follows the pattern '/model/{ModelName}'. This is useful for automatic routing in CRUD operations.

Gets the route for the component

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 535

The route path for the component, or empty string if no route is available

string

# handleClick(direction, pageopt) → {void}

Processes user interactions with the pagination component, updating the current page if specified and emitting an event with navigation details. This method is called when users click on page numbers or navigation buttons.

Handles click events on pagination controls.

sequenceDiagram participant U as User participant P as PaginationComponent participant E as External Component U->>P: Click pagination control P->>P: handleClick(direction, page?) alt page is provided P->>P: Update current page end P->>E: Emit clickEvent with direction and page
Parameters:
Name Type Attributes Description
direction 'next' | 'previous'

The direction of navigation

page number <optional>

Optional page number to navigate to directly

View Source lib/components/pagination/pagination.component.ts, line 489

void

# handleEvent(event) → {void}

Receives events from child renderer components and forwards them to parent components through the listenEvent output. This creates an event propagation chain that allows events to bubble up through the component hierarchy, enabling coordinated responses to user interactions across the layout structure.

Handles custom events from child components.

sequenceDiagram participant C as Child Component participant L as NgxBaseComponent participant P as Parent Component C->>L: Emit RendererCustomEvent L->>L: handleEvent(event) L->>P: listenEvent.emit(event) Note over P: Handle event in parent
Parameters:
Name Type Description
event RendererCustomEvent

The custom event from a child component

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 617

void

# initialize()

Performs one-time initialization of the component. This method checks if the component has already been initialized to prevent duplicate initialization. When called for the first time, it sets the initialized flag to true and logs an initialization message with the component name. This method is typically called during the component's lifecycle setup.

Initializes the component

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 591

Updates the current page to the specified page number and triggers the click event handler with the appropriate direction. This method is typically called when the user clicks directly on a page number in the pagination UI.

Navigates to a specific page number.

sequenceDiagram participant U as User participant P as PaginationComponent U->>P: Click page number P->>P: navigate(page) alt page is not null and different from current P->>P: Determine direction (next/previous) P->>P: handleClick(direction, page) end
Parameters:
Name Type Description
page number | null

The page number to navigate to

View Source lib/components/pagination/pagination.component.ts, line 597

void

# next() → {void}

Increments the current page number if not at the last page and triggers the click event handler with 'next' direction. This method is typically called when the user clicks on the "next" button in the pagination UI.

Navigates to the next page.

sequenceDiagram participant U as User participant P as PaginationComponent U->>P: Click next button P->>P: next() alt page <= max pages P->>P: Increment current page P->>P: handleClick('next') end

View Source lib/components/pagination/pagination.component.ts, line 548

void

# ngOnChanges(changes) → {void}

This Angular lifecycle hook is called when input properties change. It responds to changes in the model, locale, or translatable properties by updating the component's internal state accordingly. When the model changes, it calls getModel to process the new model and getLocale to update the locale. When locale or translatable properties change, it calls getLocale to update the translation settings.

Handles changes to component inputs

Parameters:
Name Type Description
changes SimpleChanges

Object containing changed properties

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 474

void

# ngOnInit() → {void}

Sets up the component by initializing the locale settings based on the translatable property, generating the page numbers based on the total pages and current page, and storing the last page number for boundary checking.

Initializes the component after Angular sets the input properties.

sequenceDiagram participant A as Angular Lifecycle participant P as PaginationComponent A->>P: ngOnInit() P->>P: getLocale(translatable) P->>P: Set locale P->>P: getPages(data, current) P->>P: Set pages array P->>P: Set last page number

View Source lib/components/pagination/pagination.component.ts, line 462

void

# protected parseProps(instance) → {void}

This method iterates through the properties of the provided instance object and applies any matching properties from the component's props configuration to the component instance. This allows for dynamic property assignment based on configuration stored in the props object, enabling flexible component customization without requiring explicit property binding for every possible configuration option.

The method performs a safe property assignment by checking if each key from the instance exists in the props object before applying it. This prevents accidental property overwriting and ensures only intended properties are modified.

Parses and applies properties from the props object to the component instance.

sequenceDiagram participant C as Component participant B as NgxBaseComponent participant P as Props Object C->>B: parseProps(instance) B->>B: Get Object.keys(instance) loop For each key in instance B->>P: Check if key exists in this.props alt Key exists in props B->>B: Set this[key] = this.props[key] else Key not in props Note over B: Skip this key end end
Parameters:
Name Type Description
instance KeyValue

The component instance object to process

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 456

void

# previous() → {void}

Decrements the current page number if not at the first page and triggers the click event handler with 'previous' direction. This method is typically called when the user clicks on the "previous" button in the pagination UI.

Navigates to the previous page.

sequenceDiagram participant U as User participant P as PaginationComponent U->>P: Click previous button P->>P: previous() alt page > 0 P->>P: Decrement current page P->>P: handleClick('previous') end

View Source lib/components/pagination/pagination.component.ts, line 572

void

# setModelDefinitions(model) → {void}

Extracts and applies configuration from the model's decorators to set up the component. This method uses the rendering engine to retrieve decorator metadata from the model, then configures the component's mapper and item properties accordingly. It ensures the route is properly set and merges various properties from the model's metadata into the component's configuration.

Configures component properties based on model metadata

Parameters:
Name Type Description
model Model

The model to extract configuration from

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 566

void

# trackItemFn(index, item) → {string|number}

Provides a tracking function for Angular's *ngFor directive to optimize rendering performance. This method generates unique identifiers for list items based on their index and content, allowing Angular to efficiently track changes and minimize DOM manipulations during list updates. The tracking function is essential for maintaining component state and preventing unnecessary re-rendering of unchanged items.

Tracks items in ngFor loops for optimal change detection.

Parameters:
Name Type Description
index number

The index of the item in the list

item KeyValue | string | number

The item data to track

Overrides:

View Source lib/engine/NgxBaseComponent.ts, line 633

A unique identifier for the item

string | number