# Paginator

`class` in `http` · v0.4.1

<https://docs.seedcord.org/packages/http/0.4.1/classes/paginator>

A restart-proof paginator. Each nav button's customId encodes its full target page, so clicks are idempotent and survive a restart. A persistent `@ButtonRoute` on `Handler` dispatches the clicks.

```ts
class Paginator<Item, Prefix extends string> extends PaginatorBase<
    Item,
    Prefix,
    PageContext
>
```

## Examples

```ts
export const Bans = new Paginator({
    prefix: 'bans',
    source: new ArraySource((ctx) => loadBans(ctx.guildId), { perPage: 10 }),
    renderItem: (ban) => ban.user.username
});

\@ButtonRoute(Bans.cursor)
export class BansNav extends Bans.Handler {}
```

## Constructors

### constructor

```ts
Paginator(config: PaginatorConfig<Item, Prefix, PageContext>)
```

Constructs a new instance of the `Paginator` class

## Properties

### config

```ts
protected readonly config: PaginatorConfig<Item, Prefix, Ctx>
```

### cursor

```ts
readonly cursor: PageCursor<Prefix>
```

The page cursor, pass it to your `@ButtonRoute`.

### Handler

```ts
public readonly Handler: PaginatorHandlerCtor<Prefix>
```

The nav handler base. Extend it with an empty body and decorate it, `@ButtonRoute(p.cursor)`.

## Methods

### page

```ts
async page(
    ctx: Ctx,
    n: number
): Promise<ReplyResponse>
```

Render a page as a [`ReplyResponse`](/packages/types/0.13.0/interfaces/reply-response). To post it elsewhere, add `flags: MessageFlags.IsComponentsV2`.

### start

```ts
public async start(
    handler: RepliableHandler<Repliables>
): Promise<SentMessage>
```

Render page 0 and send it through the handler's sender, which picks reply, edit, or followUp from its ack state.
