Table Component: Data Fetching & Type Safety
Data retrieval is configured via the fetchData option of the useTable hook.
The fetchData Property
The fetchData function is responsible for retrieving and returning paginated/filtered data for the table. It must return a promise that resolves to an object containing:
rows(array): The rows to render for the current page.resultCount(number, optional): The total count of rows across all pages (required for pagination).nextPage(number, optional): Page number of the next page of results.
1. Using createFetcher with SDK Functions (Recommended)
The standard approach is to pass an API client list function from waldur-js-client to createFetcher:
1 2 3 4 5 6 7 | |
Customizing Query and Path Parameters
You can pass query overrides and path parameters for nested API endpoints:
1 2 3 4 5 6 7 8 9 10 11 | |
Mapping Nested Arrays via parser
If the API returns a nested response (an object instead of a direct array), use parser to extract the rows array:
1 2 3 4 5 6 7 8 9 10 | |
2. Custom fetchData Implementation
For custom client-side mock-ups or custom HTTP requests:
1 2 3 4 5 6 7 8 9 10 11 12 | |
3. Client-Side Paginated Fetcher for Static Data
For static or local arrays that require full pagination, client-side sorting, and search matching, use createClientPaginatedFetcher:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
4. Search Query Input (queryField)
If you enable text-based search queries on the table (by passing the hasQuery prop to the Table component), you must specify queryField in the useTable options. This instructs useTable which query parameter name to use when passing the search term in the API request:
1 2 3 4 5 | |
Type Safety
The Table component supports TypeScript type inference.
1. Automatic Type Inference
When using createFetcher with SDK functions, the row type is automatically inferred from the SDK function's return type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
2. Explicit Type Parameter
For custom fetchers or when you need explicit control, pass the generic row type directly to Table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |