How to implement pagination with FT4
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
- Docker (for local blockchain)
- Node.js
- FT4 client
- Postchain client
Demo script
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:
userwithnamefield for demonstration - Query:
get_users_paginatedwithpage_sizeandpage_cursorparameters returning FT4-style result withdataandnext_cursor - Operation:
add_userfor seeding test data
JavaScript Client
- First page request - Fetches initial data with
page_cursorset to null - Subsequent pages - Uses
next_cursorfrom 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_rowidto handle cursor positioning - Employs
ft4_utils.pagination_resultfor data formatting - Utilizes
ft4_utils.fetch_data_sizefor proper page sizing - Returns results via
ft4_utils.make_pagefor standardized response format
Client Usage Pattern
The JavaScript client demonstrates the standard pagination flow:
- Initial request sets
page_cursorto null for the first page - Subsequent requests use the
next_cursorvalue 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 — covers FT4 operations and utilities.
- Rell language — understanding how to create queries and operations in Rell.
- JavaScript/TypeScript client — covers client setup and usage.