# Table Pagination URL: /react/components/table-pagination Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/table-pagination.mdx A component that controls both the page of a data table and the number of rows displayed per page. 사용 가능 버전: @seed-design/react-pagination@1.0.0, @seed-design/css@2.6.0 ## Preview ```tsx import { Box } from "@seed-design/react"; import { TablePagination } from "seed-design/ui/table-pagination"; export default function TablePaginationPreview() { return ( ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:table-pagination - pnpm: pnpm dlx @seed-design/cli@latest add ui:table-pagination - yarn: yarn dlx @seed-design/cli@latest add ui:table-pagination - bun: bun x @seed-design/cli@latest add ui:table-pagination ## Usage ```tsx import { TablePagination } from "seed-design/ui/table-pagination"; ``` If you know the total number of data items, pass `totalItems`. The component calculates the current range, total count, and navigability. Table Pagination always displays on one line. On narrow screens, place the table and Table Pagination in the same `overflow-x: auto` container to provide horizontal scrolling. Use only at the bottom of a data table. For navigating pages in general lists, use [Pagination](/react/components/pagination). The default rows-per-page options are 10, 25, and 50, and it is recommended to keep the choices to about 3-4. ## Localization Modify `numberFormatter` and `tablePaginationText` at the top of the snippet file to match your app's language. You can change the range, total count, rows per page, and accessibility names of each control in one place. ## Props ## Examples ### Controlled `value` manages `page` and `pageSize` as one value. When you change the rows per page, the page is reset to 1 and `onValueChange` is called once. ```tsx "use client"; import { Box, Text, VStack } from "@seed-design/react"; import { useState } from "react"; import { TablePagination, type TablePaginationValue } from "seed-design/ui/table-pagination"; export default function TablePaginationControlled() { const [value, setValue] = useState({ page: 3, pageSize: 25 }); return ( {value.page}페이지 · 페이지당 {value.pageSize}개 ); } ``` ### onValueChange Details The second argument of `onValueChange` provides `reason` indicating the cause of change and `previousValue` being the value before change. | reason | Condition | | ------------ | -------------------------------------------------------------------- | | `previous` | When the previous page button is selected | | `next` | When the next page button is selected | | `page-range` | When the display range is selected | | `page-size` | When rows per page is changed | | `constraint` | When an externally provided page is out of valid range and corrected | When an external page is out of range, the corrected value is rendered first, and then the `constraint` change is notified once. ### Unknown Total If you do not yet know the total count, omit `totalItems` and pass `hasPreviousPage` and `hasNextPage`. In this mode, the current range is displayed as text and the total count and page range selector are not displayed. Passing `currentPageItemCount` accurately displays a range with fewer rows like the last page. If omitted, it assumes there are `pageSize` rows, and if a value larger than `pageSize` comes in temporarily, it is corrected to `pageSize`. ```tsx "use client"; import { Box } from "@seed-design/react"; import { useState } from "react"; import { TablePagination, type TablePaginationValue } from "seed-design/ui/table-pagination"; export default function TablePaginationUnknownTotal() { const [value, setValue] = useState({ page: 2, pageSize: 10 }); return ( 1} hasNextPage={value.page < 5} currentPageItemCount={value.page === 5 ? 7 : value.pageSize} aria-label="전체 개수를 알 수 없는 상품 표 페이지" /> ); } ``` ### Empty When there is no data, `0-0 / Total 0 items` is displayed. The page range selector and previous/next buttons are disabled, but you can change the rows per page. ```tsx import { Box } from "@seed-design/react"; import { TablePagination } from "seed-design/ui/table-pagination"; export default function TablePaginationEmpty() { return ( ); } ``` ## Large Data Sets If the number of pages is 200 or less, all page ranges are automatically displayed. If it exceeds 200, only a maximum of 200 pages are displayed by combining the first page, last page, and pages around the current page. To directly choose which pages to display, pass `pageOptions`. All provided options are rendered and the current page is automatically included even if not in the options, so it's best to avoid large arrays. ## Accessibility The root is rendered as a group that bundles rows-per-page setting and page navigation. The default accessibility name is `Table page navigation`, and if there are multiple tables on the same screen, distinguish them using `aria-label` or `aria-labelledby`. Provide loading state and result guidance after changing pages not in Table Pagination but in the linked data table area.