diff --git a/packages/tanstack-table-search-params/src/encoder-decoder/pagination.test.ts b/packages/tanstack-table-search-params/src/encoder-decoder/pagination.test.ts index 58a67b0..2efb101 100644 --- a/packages/tanstack-table-search-params/src/encoder-decoder/pagination.test.ts +++ b/packages/tanstack-table-search-params/src/encoder-decoder/pagination.test.ts @@ -15,7 +15,7 @@ describe("pagination", () => { { name: "basic", pagination: { pageIndex: 2, pageSize: 50 }, - want: { pageIndex: "2", pageSize: "50" }, + want: { pageIndex: "3", pageSize: "50" }, }, { name: "default pageIndex and pageSize", @@ -30,7 +30,7 @@ describe("pagination", () => { { name: "default pageSize", pagination: { pageIndex: 2, pageSize: defaultPagination.pageSize }, - want: { pageIndex: "2", pageSize: undefined }, + want: { pageIndex: "3", pageSize: undefined }, }, { name: "0 pageIndex and pageSize", @@ -45,7 +45,7 @@ describe("pagination", () => { { name: "0 pageSize", pagination: { pageIndex: 2, pageSize: 0 }, - want: { pageIndex: "2", pageSize: "0" }, + want: { pageIndex: "3", pageSize: "0" }, }, ])("$name", ({ pagination, want }) => expect(encodePagination(pagination)).toEqual(want), @@ -60,7 +60,7 @@ describe("pagination", () => { { name: "basic", queryValues: { pageIndex: "2", pageSize: "25" }, - want: { pageIndex: 2, pageSize: 25 }, + want: { pageIndex: 1, pageSize: 25 }, }, { name: "invalid pageIndex and pageSize", @@ -75,7 +75,7 @@ describe("pagination", () => { { name: "invalid pageSize", queryValues: { pageIndex: "2", pageSize: "foo" }, - want: { pageIndex: 2, pageSize: defaultPagination.pageSize }, + want: { pageIndex: 1, pageSize: defaultPagination.pageSize }, }, { name: "undefined pageIndex and pageSize", @@ -85,7 +85,7 @@ describe("pagination", () => { { name: "undefined pageSize", queryValues: { pageIndex: "2", pageSize: undefined }, - want: { pageIndex: 2, pageSize: defaultPagination.pageSize }, + want: { pageIndex: 1, pageSize: defaultPagination.pageSize }, }, { name: "undefined pageIndex", @@ -105,7 +105,7 @@ describe("pagination", () => { { name: "empty pageSize", queryValues: { pageIndex: "2", pageSize: "" }, - want: { pageIndex: 2, pageSize: defaultPagination.pageSize }, + want: { pageIndex: 1, pageSize: defaultPagination.pageSize }, }, { name: "0 pageIndex and pageSize", @@ -120,7 +120,7 @@ describe("pagination", () => { { name: "pageSize is 0", queryValues: { pageIndex: "2", pageSize: "0" }, - want: { pageIndex: 2, pageSize: 0 }, + want: { pageIndex: 1, pageSize: 0 }, }, ])("$name", ({ queryValues, want }) => expect(decodePagination(queryValues)).toEqual(want), diff --git a/packages/tanstack-table-search-params/src/encoder-decoder/pagination.ts b/packages/tanstack-table-search-params/src/encoder-decoder/pagination.ts index 8e77807..d44c5fd 100644 --- a/packages/tanstack-table-search-params/src/encoder-decoder/pagination.ts +++ b/packages/tanstack-table-search-params/src/encoder-decoder/pagination.ts @@ -15,7 +15,7 @@ export const encodePagination = ( pageIndex: pagination.pageIndex === defaultPagination.pageIndex ? undefined - : pagination.pageIndex.toString(), + : (pagination.pageIndex + 1).toString(), pageSize: pagination.pageSize === defaultPagination.pageSize ? undefined @@ -30,9 +30,9 @@ export const decodePagination = (queryValues: { const pageSize = Number(queryValues.pageSize); return { pageIndex: - queryValues.pageIndex === "" || Number.isNaN(pageIndex) + queryValues.pageIndex === "" || Number.isNaN(pageIndex) || pageIndex < 1 ? defaultPagination.pageIndex - : pageIndex, + : pageIndex - 1, pageSize: queryValues.pageSize === "" || Number.isNaN(pageSize) ? defaultPagination.pageSize diff --git a/packages/tanstack-table-search-params/src/tests/next-pages-router/pagination.test.ts b/packages/tanstack-table-search-params/src/tests/next-pages-router/pagination.test.ts index 192edd5..39cc368 100644 --- a/packages/tanstack-table-search-params/src/tests/next-pages-router/pagination.test.ts +++ b/packages/tanstack-table-search-params/src/tests/next-pages-router/pagination.test.ts @@ -146,7 +146,7 @@ describe("pagination", () => { pageIndex: 1, pageSize: 20, }) ?? { - [paramName.pageIndex]: "1", + [paramName.pageIndex]: "2", [paramName.pageSize]: "20", }, ); diff --git a/packages/tanstack-table-search-params/src/tests/pagination.test.ts b/packages/tanstack-table-search-params/src/tests/pagination.test.ts index 72f988c..cea59b7 100644 --- a/packages/tanstack-table-search-params/src/tests/pagination.test.ts +++ b/packages/tanstack-table-search-params/src/tests/pagination.test.ts @@ -147,7 +147,7 @@ describe("pagination", () => { pageIndex: 1, pageSize: 20, }) ?? { - [paramName.pageIndex]: "1", + [paramName.pageIndex]: "2", [paramName.pageSize]: "20", }, );