# Pagination

Display a series of buttons to navigate through a list of items.

```tsx
import { Pagination } from '@fluxui-dev/react';

// orders: Order::paginate(), passed as a page prop
<Pagination paginator={orders} />
```

## Simple paginator

Use the simple paginator when working with large datasets where counting the total number of results would be expensive. The simple paginator provides "Previous" and "Next" buttons without displaying the total number of pages or records.

```tsx
// orders: Order::simplePaginate(), passed as a page prop
<Pagination paginator={orders} />
```

## Large result set

When working with large result sets, the pagination component automatically adapts to show a reasonable number of page links. It shows the first and last pages, along with a window of pages around the current page, and adds ellipses for any gaps to ensure efficient navigation through numerous pages.

```tsx
// orders: Order::paginate(5), passed as a page prop
<Pagination paginator={orders} />
```

## Scroll to top

Use the `scrollTo` prop to scroll the page when a pagination button is clicked. By default, it scrolls to the `body` element.

```tsx
<Pagination paginator={orders} scrollTo />
```

You can also target a specific element by passing a CSS selector.

```tsx
<Pagination paginator={orders} scrollTo="#table" />
```

## Paging in the browser

Pass `onPageChange` to handle page changes yourself, such as for data that's already loaded, and build the paginator from your own state.

```tsx
import { useState } from 'react';

const [page, setPage] = useState(1);

<Pagination
    paginator={{ current_page: page, last_page: 10, total: 95, from: (page - 1) * 10 + 1, to: Math.min(page * 10, 95) }}
    onPageChange={setPage}
/>
```

## Reference

### Pagination

**Prop:**

- `paginator` - The paginator to display: what Laravel's `paginate()`, `simplePaginate()`, or `cursorPaginate()` returns, or an API resource collection of one. Page links navigate through the link registered in `FluxProvider`.
- `onPageChange` - Callback fired with the page number when a page button is clicked, instead of following the paginator's URLs. Ignored for cursor paginators.
- `scrollTo` - Scroll to an element when a pagination button is clicked. Pass a CSS selector to target a specific element. Default: `body`.
- `className` - CSS classes applied to the pagination's root element.

**Attribute:**

- `data-flux-pagination` - Applied to the root element for styling and identification.
