From c9193921fbb52be4e84660b8a9efb9f4b991790f Mon Sep 17 00:00:00 2001 From: "LT. Sana" Date: Tue, 21 Oct 2025 16:10:42 +0300 Subject: [PATCH 1/2] Updated the documentation for pagination --- documentation/docs/pagination.md | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/documentation/docs/pagination.md b/documentation/docs/pagination.md index bc68a641..c837ee3e 100644 --- a/documentation/docs/pagination.md +++ b/documentation/docs/pagination.md @@ -403,3 +403,65 @@ const { "personal_information.personal_information_id, personal_information.created_at" ); ``` + +#### Using the `formatParams` Hook + +Another way of managing pagination on the frontend, you can utilize the `formatParams` hook, which facilitates various pagination functionalities and data retrieval. This method returns a string that can be passed directly to your URL. + +```javascript +import { DIRECTION, Filter, formatParams } from '@xest-ui/data-table'; + +const filters: Filter[] = []; + +let search = "john"; // Users name to be searched +let pageSize: 5 | 10 | 25 = 5; // Recommended 3 options +let cursor = "__base64_string__"; // Found in metadata after a request +let direction: DIRECTION.NEXT | DIRECTION.PREVIOUS = DIRECTION.NEXT; +let sortBy = "myTable.id"; + +filters.push({ + column: "myTable.firstName", + operation: "contains", + values: [search] +}); + +const reqParams = formatParams({ + page_size: pageSize, + filters: filters, + cursor: cursor, + direction: direction, + sort_by: sortBy +}); + +const res = await getUsers(organizationId, reqParams); + +``` + +#### Using hardcoded string + +You can also make a hardcoded string to set the page size, filter, set the cursor and direction and sort the order. Not recommended. + +```javascript + +const bookId = 1; + +const params = [ + `page_size=5`, + `sort_by=-bookTable.created_at`, + + // Filters + `filters[0][column]=bookTable.returned_date`, + `filters[0][operation]=isNotNull`, // Check if the date is not null + + `filters[1][column]=bookTable.id`, + `filters[1][operation]=equals`, + `filters[1][values][0]=${notedId}` // Get the book with that ID + + // Pagination + `direction=next`, // 2 options (next & previous) + `cursor=__base64_string__` +]; + +const res = getBooks(organizationId, params.join("&")) + +``` From 3924a6dc23770f5a0b68772ffc1dcea3567e2f38 Mon Sep 17 00:00:00 2001 From: "LT. Sana" Date: Wed, 22 Oct 2025 11:57:06 +0300 Subject: [PATCH 2/2] Removed the hardcoded strings and cursors --- documentation/docs/pagination.md | 42 ++++++-------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/documentation/docs/pagination.md b/documentation/docs/pagination.md index c837ee3e..d815379e 100644 --- a/documentation/docs/pagination.md +++ b/documentation/docs/pagination.md @@ -414,10 +414,13 @@ import { DIRECTION, Filter, formatParams } from '@xest-ui/data-table'; const filters: Filter[] = []; let search = "john"; // Users name to be searched -let pageSize: 5 | 10 | 25 = 5; // Recommended 3 options -let cursor = "__base64_string__"; // Found in metadata after a request -let direction: DIRECTION.NEXT | DIRECTION.PREVIOUS = DIRECTION.NEXT; -let sortBy = "myTable.id"; +let pageSize = 50; + +// How to use single column to sort (- prefix desc / no prefix asc) +let sortBy = "-myTable.id"; + +// How to use multiple columns to sort (using comma to separate) +let sortBy = "-myTable.id,-myTable.created_at"; filters.push({ column: "myTable.firstName", @@ -428,40 +431,9 @@ filters.push({ const reqParams = formatParams({ page_size: pageSize, filters: filters, - cursor: cursor, - direction: direction, sort_by: sortBy }); const res = await getUsers(organizationId, reqParams); ``` - -#### Using hardcoded string - -You can also make a hardcoded string to set the page size, filter, set the cursor and direction and sort the order. Not recommended. - -```javascript - -const bookId = 1; - -const params = [ - `page_size=5`, - `sort_by=-bookTable.created_at`, - - // Filters - `filters[0][column]=bookTable.returned_date`, - `filters[0][operation]=isNotNull`, // Check if the date is not null - - `filters[1][column]=bookTable.id`, - `filters[1][operation]=equals`, - `filters[1][values][0]=${notedId}` // Get the book with that ID - - // Pagination - `direction=next`, // 2 options (next & previous) - `cursor=__base64_string__` -]; - -const res = getBooks(organizationId, params.join("&")) - -```