Raw
1 import { createDataTableColumnHelper, useDataTable, DataTable, Heading } from "@medusajs/ui"
2
3 const products = [
4 {
5 id: "1",
6 title: "Shirt",
7 price: 10
8 },
9 {
10 id: "2",
11 title: "Pants",
12 price: 20
13 }
14 ]
15
16 const columnHelper = createDataTableColumnHelper<typeof products[0]>()
17
18 const columns = [
19 columnHelper.accessor("title", {
20 header: "Title",
21 enableSorting: true,
22 }),
23 columnHelper.accessor("price", {
24 header: "Price",
25 enableSorting: true,
26 }),
27 ]
28
29 export default function ProductTable () {
30 const table = useDataTable({
31 columns,
32 data: products,
33 getRowId: (product) => product.id,
34 rowCount: products.length,
35 isLoading: false,
36 })
37
38 return (
39 <DataTable instance={table}>
40 <DataTable.Toolbar className="flex flex-col items-start justify-between gap-2 md:flex-row md:items-center">
41 <Heading>Products</Heading>
42 </DataTable.Toolbar>
43 <DataTable.Table />
44 </DataTable>
45 )
46 }