With Pagination
Example using the Pagination component.
import { createColumns, Table, THead, THeadCell, TBody, TBodyRow, TBodyCell, useTableState, DataView, DataViewHeader, useDataViewState, IconEye, csx, Tag, Pagination, usePaginationState, FlexSpacer, } from '@vtex/admin-ui' import faker from 'faker' const NUMBER_OF_ITEMS = 100 const ITEMS_PER_PAGE = 5 const items = Array(NUMBER_OF_ITEMS) .fill() .map((_, id) => { return { id, name: faker.commerce.productName(), brand: faker.random.arrayElement([ 'Revolution', 'Desire Spirit', 'Pathway', 'AeroSmart', 'Quality Prints', 'Traction Race', ]), price: faker.commerce.price(), status: 'Inactive', } }) const columns = createColumns([ { id: 'name', header: 'Name', width: '2fr', resolver: { type: 'text', columnType: 'name', mapText: (item) => item.name, render: ({ data }) => ( <div className={csx({ minWidth: '10rem' })}>{data}</div> ), }, }, { id: 'brand', header: 'Brand', width: '1fr', resolver: { type: 'root', render: ({ item }) => { return <div className={csx({ minWidth: '6rem' })}>{item.brand}</div> }, }, }, { id: 'price', header: 'Price', width: '1fr', resolver: { type: 'currency', locale: 'en-US', currency: 'USD', }, }, { id: 'status', header: 'Status', width: '1fr', resolver: { type: 'root', render: ({ item }) => { return <Tag label={item.status} size="normal" /> }, }, }, { resolver: { type: 'menu', actions: [ { label: 'View details', icon: <IconEye />, }, ], }, }, ]) export default function App() { const view = useDataViewState() const pagination = usePaginationState({ pageSize: ITEMS_PER_PAGE, total: NUMBER_OF_ITEMS, }) const { data, getBodyCell, getHeadCell, getTable } = useTableState({ status: view.status, columns, items: items.slice(pagination.range[0] - 1, pagination.range[1]), length: ITEMS_PER_PAGE, }) return ( <DataView state={view}> <DataViewHeader> <FlexSpacer /> <Pagination state={pagination} /> </DataViewHeader> <Table {...getTable()}> <THead> {columns.map((column) => ( <THeadCell {...getHeadCell(column)} /> ))} </THead> <TBody> {data.map((item) => { return ( <TBodyRow key={item.id} onClick={() => alert('Item: item.name')} > {columns.map((column) => { return <TBodyCell {...getBodyCell(column, item)} /> })} </TBodyRow> ) })} </TBody> </Table> </DataView> ) }