@mantlebee/ts-data
    Preparing search index...

    Interface IPaginationExtension<TItem>

    Extension that adds a Pagination to the payload and keeps the total count up to date. Pages are 1-based and always clamped to [1, lastPage]. By default a change of the query built by the previous extensions (filters, sorts, ...) between two reads brings the page back to 1 (PaginationExtensionOptions.resetPageOnQueryChange). Every event is raised only when the value actually changes (see PaginationExtensionEvents).

    interface IPaginationExtension<TItem = Any> {
        canGoNextPage: boolean;
        canGoPreviousPage: boolean;
        itemsPerPage: number;
        itemsPerPageOptions?: List<number>;
        lastPage: number;
        page: number;
        totalItemsCount: number;
        buildPayload?(
            payload: DataSourcePayload<TItem>,
            signal?: AbortSignal,
        ): Promise<DataSourcePayload<TItem>>;
        dispose(): Promise<void>;
        goToFirstPage(): void;
        goToLastPage(): void;
        goToNextPage(): void;
        goToPage(page: number): void;
        goToPreviousPage(): void;
        on<TKey extends string>(
            event: TKey,
            handler: EventHandler<PaginationExtensionEvents, TKey>,
        ): IDisposable;
        readItems?(
            payload: DataSourcePayload<TItem>,
            next: DataSourceReadNext<TItem>,
            signal?: AbortSignal,
        ): Promise<List<TItem>>;
        setItemsPerPage(itemsPerPage: number): void;
    }

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implemented by

    Index
    canGoNextPage: boolean

    true when page is not the last one.

    canGoPreviousPage: boolean

    true when page is not the first one.

    itemsPerPage: number

    Size of a page, a positive integer.

    itemsPerPageOptions?: List<number>

    Allowed values of itemsPerPage, when restricted.

    lastPage: number

    Number of pages, at least 1: ceil(totalItemsCount / itemsPerPage).

    page: number

    Current page, from 1 to lastPage.

    totalItemsCount: number

    Total count of the last read, 0 before the first.

    • Releases the held resource. Implementations should be safe to call more than once.

      Returns Promise<void>

      a promise that settles once the resource has been released.

    • Goes to a page. Raises page only when the (clamped) target differs from the current page.

      Parameters

      • page: number

        Target page, truncated to an integer and clamped to [1, lastPage].

      Returns void

    • Registers a handler for an event.

      Type Parameters

      • TKey extends string

        Name of the event to listen to.

      Parameters

      Returns IDisposable

      a subscription; dispose it to remove this single handler.

    • Wraps the reading of the items. Read phase: the extension is a layer of the onion around the reader, next the layers inside it (the inner extensions, then the reader of the data source). The payload is the whole query, whatever the position of the extension.

      next may be called zero times (e.g. a cache hit: the reader is never invoked), once, with this or another payload, or several times (e.g. a payload split into several reads whose results are merged); every call runs the inner layers and the reader again, so the hooks and the events of the inner extensions may fire as many times. The result may be transformed before being returned, and flows outward: the outermost extension transforms last.

      Parameters

      • payload: DataSourcePayload<TItem>

        The whole query, built by the build phase.

      • next: DataSourceReadNext<TItem>

        Reads the items through the inner layers and the reader; the signal of the read is bound already.

      • Optionalsignal: AbortSignal

        Signal of the read, aborted when the read is superseded, for the reads of the extension itself.

      Returns Promise<List<TItem>>

      the items for the outer extension, or the data source.