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