# How to implement pagination with FT4 · Chromia Docs (concept)

> This recipe demonstrates how to implement cursor-based pagination using FT4 utilities in Rell and consume it from a client.

Source: https://docs.chromia.com/build/cookbook/query-creation/pagination-with-ft4/

# How to implement pagination with FT4

On this page

* [Prerequisites](#prerequisites)
* [Demo script](#demo-script)
* [Key Features](#key-features)
* [Architecture Overview](#architecture-overview)
* [Rell Module (Server-side)](#rell-module-server-side)
* [JavaScript Client](#javascript-client)
* [FT4 Pagination Pattern](#ft4-pagination-pattern)
* [Client Usage Pattern](#client-usage-pattern)
* [Use Cases](#use-cases)
* [Learn more](#learn-more)

This recipe demonstrates how to implement cursor-based pagination using FT4 utilities in Rell and consume it from a
client. This approach is ideal for projects already using FT4, as it leverages pagination helpers from `lib.ft4.utils`
for consistent cursor handling.

JS/TS client

## Prerequisites

* [Chromia CLI](https://docs.chromia.com/get-started/installation/)
* **Docker** (for local blockchain)
* **Node.js**
* [FT4 client](https://docs.chromia.com/build/ft4/intro/#client)
* [Postchain client](https://docs.chromia.com/build/clients/overview/)

## Demo script

* [Pagination with FT4 demo](https://bitbucket.org/chromawallet/recipes/src/main/pagination_with_ft4/)

## Key Features

This recipe includes examples for:

* **Cursor-based pagination** - Using FT4's cursor system for efficient data traversal
* **Rell implementation** - Server-side pagination logic using `lib.ft4.utils`
* **Client consumption** - JavaScript client that handles pagination requests
* **Consistent pagination** - Following FT4 patterns for standardized pagination across your dapp

## Architecture Overview

The recipe includes both server and client components:

### Rell Module (Server-side)

* **Entity**: `user` with `name` field for demonstration
* **Query**: `get_users_paginated` with `page_size` and [`page_cursor`](https://docs.chromia.com/pages/ft4-rell/-f-t4-library/lib.ft4.utils/page_cursor/) parameters returning FT4-style result with `data`
  and `next_cursor`
* **Operation**: `add_user` for seeding test data

### JavaScript Client

* **First page request** - Fetches initial data with [`page_cursor`](https://docs.chromia.com/pages/ft4-rell/-f-t4-library/lib.ft4.utils/page_cursor/) set to null
* **Subsequent pages** - Uses `next_cursor` from previous response
* **Page size control** - Configurable page size per request

## FT4 Pagination Pattern

The Rell implementation uses FT4 utilities for consistent pagination:

* Uses `ft4_utils.before_rowid` to handle cursor positioning
* Employs `ft4_utils.pagination_result` for data formatting
* Utilizes `ft4_utils.fetch_data_size` for proper page sizing
* Returns results via `ft4_utils.make_page` for standardized response format

## Client Usage Pattern

The JavaScript client demonstrates the standard pagination flow:

* Initial request sets [`page_cursor`](https://docs.chromia.com/pages/ft4-rell/-f-t4-library/lib.ft4.utils/page_cursor/) to null for the first page
* Subsequent requests use the `next_cursor` value from previous responses
* Page size can be adjusted per request for flexible data loading

## Use Cases

This pagination approach is ideal for:

* **Large datasets** - Efficiently browsing through extensive records
* **User interfaces** - Implementing paginated lists and tables
* **API endpoints** - Providing paginated data to frontend applications
* **Performance optimization** - Reducing memory usage and response times

## Learn more

* [FT4 client documentation](https://docs.chromia.com/build/clients/ft4-client/) — covers FT4 operations and utilities.
* [Rell language](https://docs.chromia.com/rell/rell-intro/) — understanding how to create queries and operations in Rell.
* [JavaScript/TypeScript client](https://docs.chromia.com/build/clients/postchain-clients/javascript-typescript/reference/) — covers client setup and
  usage.

[View this page on docs.chromia.com](https://docs.chromia.com/build/cookbook/query-creation/pagination-with-ft4/)Content mirrored from the live docs
