diff --git a/apps/site/src/demos/dataTableDemo.tsx b/apps/site/src/demos/dataTableDemo.tsx index 0b7edbee5..a7d8aa55a 100644 --- a/apps/site/src/demos/dataTableDemo.tsx +++ b/apps/site/src/demos/dataTableDemo.tsx @@ -9,6 +9,7 @@ import { TagColumnProps, DropdownColumnProps, DateColumnProps, + CursorDirection, } from '../../../../packages/blend/lib/components/DataTable/types' import DataTable from '../../../../packages/blend/lib/components/DataTable/DataTable' import { Avatar } from '../../../../packages/blend/lib/components/Avatar' @@ -717,6 +718,58 @@ const SimpleDataTableExample = () => { ) } + // Cursor-based pagination state and handlers + const [useCursorPagination, setUseCursorPagination] = useState(false) + const [cursorState, setCursorState] = useState<{ + afterId?: number + beforeId?: number + } | null>(null) + const [hasNextPage, setHasNextPage] = useState(true) + const [hasPrevPage, setHasPrevPage] = useState(false) + + // Generate mock data for cursor pagination + const generatePageData = (startId: number) => { + return Array.from({ length: 5 }, (_, i) => { + const id = startId + i + const original = productData[i % productData.length] + return { + ...original, + id, + name: `${original.name || 'Product'} (Item ${id})`, + } + }) + } + + const handleCursorPageChange = ( + direction: CursorDirection, + _cursor: unknown, + _limit: number + ) => { + if (direction === CursorDirection.NEXT) { + const nextId = productTableData[productTableData.length - 1].id + 1 + const newData = generatePageData(nextId) + setProductTableData(newData) + setCursorState({ + afterId: nextId - 1, + }) + setHasNextPage(nextId < 50) + setHasPrevPage(true) + } else { + const prevId = Math.max(1, productTableData[0].id - 5) + const newData = generatePageData(prevId) + setProductTableData(newData) + setCursorState( + prevId > 1 + ? { + beforeId: prevId - 1, + } + : null + ) + setHasNextPage(true) + setHasPrevPage(prevId > 1) + } + } + return (