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