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

    Class PaginationExtension<TItem>

    Reads the total count with its own reader on every read, then adds the Pagination to the payload. Place it after the extensions whose contribution the count must consider (filters above all). The count reader receives the signal of the read, so it can hand it to fetch. By default it goes back to the first page when the query built by the previous extensions changes between two reads (PaginationExtensionOptions.resetPageOnQueryChange).

    const countUsers = (payload, signal) => api.countUsers(payload, { signal });
    const pagination = new PaginationExtension<User>(countUsers, 20, [10, 20, 50]);
    const dataSource = createDataSource(readUsers, { filtering, pagination });
    pagination.on("page", () => dataSource.read());
    await dataSource.read(); // countUsers(payload) then readUsers({ ..., pagination: { page: 1, itemsPerPage: 20, totalItemsCount } })
    pagination.goToNextPage(); // page event (if there is a second page), hence a new read

    Type Parameters

    • TItem = Any

      Type of the items.

    Hierarchy (View Summary)

    Implements

    Index
    _changeDelay: number
    _eventBus: EventBus<PaginationExtensionEvents>

    Bus used to register handlers and to raise the events.

    _itemsPerPage: number
    _itemsPerPageOptions?: List<number>
    _page: number = 1
    _resetPageOnQueryChange: boolean | List<keyof DataSourcePayload<TItem>>
    _totalCountReader: DataSourceReader<TItem, number>
    _totalItemsCount: number = 0
    • 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.