moi-computer 0.11.0 → 0.11.1-dev.be1ed10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +2 -2
  2. package/client/AGENTS.md +2 -2
  3. package/client/app/AppRouter.tsx +2 -2
  4. package/client/app/routes/WorkspaceRoute.tsx +7 -9
  5. package/client/app/shell/SidebarLayout.tsx +18 -15
  6. package/client/components/shared/BottomPanel.tsx +26 -14
  7. package/client/components/shared/PanelHeader.tsx +1 -1
  8. package/client/components/shared/ReorderableList.tsx +7 -2
  9. package/client/components/shared/WorkspaceIcon.tsx +92 -0
  10. package/client/components/ui/alert-dialog.tsx +1 -0
  11. package/client/components/ui/button.tsx +1 -53
  12. package/client/components/ui/checkbox.tsx +1 -0
  13. package/client/components/ui/collapsible.tsx +1 -15
  14. package/client/components/ui/dialog.tsx +1 -58
  15. package/client/components/ui/dropdown-menu.tsx +1 -254
  16. package/client/components/ui/hover-card.tsx +1 -44
  17. package/client/components/ui/inline-input.tsx +84 -0
  18. package/client/components/ui/input.tsx +1 -21
  19. package/client/components/ui/popover.tsx +1 -88
  20. package/client/components/ui/resizable.tsx +1 -40
  21. package/client/components/ui/skeleton.tsx +1 -13
  22. package/client/components/ui/slider.tsx +1 -70
  23. package/client/components/ui/spinner.tsx +1 -18
  24. package/client/components/ui/switch.tsx +1 -23
  25. package/client/components/ui/tabs.tsx +1 -0
  26. package/client/components/ui/textarea.tsx +1 -18
  27. package/client/components/ui/toast.tsx +2 -2
  28. package/client/components/ui/tooltip.tsx +1 -51
  29. package/client/features/applets/AppletMount.tsx +1 -1
  30. package/client/features/applets/applet-cache.ts +3 -3
  31. package/client/features/applets/applet-runtime.ts +147 -108
  32. package/client/features/applets/applet-styles.ts +2 -2
  33. package/client/features/applets/applet-thumbnail.ts +6 -8
  34. package/client/features/applets/useApplet.ts +10 -9
  35. package/client/features/chat/ChatPanel.tsx +24 -15
  36. package/client/features/chat/ChatPopup.tsx +9 -5
  37. package/client/features/chat/applet-chat-intents.ts +170 -0
  38. package/client/features/chat/chat-send.ts +116 -64
  39. package/client/features/chat/chat-store.ts +51 -62
  40. package/client/features/chat/composer/ChatComposer.tsx +43 -128
  41. package/client/features/chat/composer/ModelPicker.tsx +47 -60
  42. package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
  43. package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
  44. package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
  45. package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
  46. package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
  47. package/client/features/chat/composer/attachments/types.ts +25 -0
  48. package/client/features/chat/composer/attachments/uploads.ts +26 -0
  49. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  50. package/client/features/chat/composer/model-order.ts +15 -0
  51. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  52. package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
  53. package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
  54. package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
  55. package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
  56. package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +27 -19
  57. package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
  58. package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
  59. package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
  60. package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
  61. package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +2 -5
  62. package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
  63. package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
  64. package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
  65. package/client/features/chat/sessions/session-view.ts +53 -0
  66. package/client/features/chat/useChat.ts +42 -24
  67. package/client/features/dev/ChatStatesPage.tsx +8 -7
  68. package/client/features/dev/DevIndexPage.tsx +5 -0
  69. package/client/features/dev/DevRoutes.tsx +2 -0
  70. package/client/features/dev/HarnessDebugPage.tsx +11 -8
  71. package/client/features/dev/ToolCallsPage.tsx +1 -1
  72. package/client/features/dev/UiComponentPreviews.tsx +855 -0
  73. package/client/features/dev/UiComponentsPage.tsx +60 -0
  74. package/client/features/dev/chat-states-fixtures.ts +13 -2
  75. package/client/features/drawings/useChatAnnotation.ts +17 -17
  76. package/client/features/drawings/useDrawingLayer.ts +7 -9
  77. package/client/features/drawings/useViewBuilderSketch.ts +18 -15
  78. package/client/features/home/HomePage.tsx +8 -7
  79. package/client/features/home/WorkspacePreview.tsx +2 -2
  80. package/client/features/home/workspace-presentation.tsx +1 -11
  81. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  82. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  83. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
  84. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  85. package/client/features/overview/HiddenPanel.tsx +109 -0
  86. package/client/features/overview/Overview.tsx +302 -0
  87. package/client/features/overview/WidgetCanvas.tsx +164 -0
  88. package/client/features/{widgets → overview}/WidgetFrame.tsx +25 -17
  89. package/client/features/overview/WorkspaceName.tsx +60 -0
  90. package/client/features/overview/api.ts +30 -0
  91. package/client/features/overview/default/ViewsWidget.tsx +252 -0
  92. package/client/features/overview/default/registry.tsx +36 -0
  93. package/client/features/{widgets → overview}/grid.ts +36 -0
  94. package/client/features/overview/useGridReconcile.ts +94 -0
  95. package/client/features/scratchpad/Scratchpad.tsx +7 -8
  96. package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
  97. package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
  98. package/client/features/settings/GeneralSettings.tsx +55 -58
  99. package/client/features/settings/SettingsLayout.tsx +2 -2
  100. package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
  101. package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
  102. package/client/features/settings/api.ts +48 -24
  103. package/client/features/views/ViewBuilder.tsx +5 -4
  104. package/client/features/views/ViewManager.tsx +25 -22
  105. package/client/features/views/api.ts +36 -2
  106. package/client/features/views/useViewBuilderActions.ts +8 -5
  107. package/client/features/views/useViewBuilderDrafts.ts +23 -21
  108. package/client/features/views/view-presentation.ts +13 -0
  109. package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
  110. package/client/features/workspace/UnavailablePage.tsx +21 -0
  111. package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
  112. package/client/features/workspace/WorkspaceScreen.tsx +210 -162
  113. package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
  114. package/client/features/workspace/WorkspaceTabs.tsx +2 -0
  115. package/client/features/workspace/api.ts +2 -30
  116. package/client/features/workspace/moi-context.ts +8 -9
  117. package/client/features/workspace/tab-resolution.ts +10 -33
  118. package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
  119. package/client/index.css +23 -30
  120. package/client/lib/app-icon-registry.ts +2 -0
  121. package/client/lib/use-latest-ref.ts +11 -0
  122. package/client/main.tsx +1 -1
  123. package/client/runtime/useWorkspaceEvents.ts +59 -14
  124. package/client/theme.css +5 -5
  125. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  126. package/dist/chunk-691pqsj6.js +2 -0
  127. package/dist/chunk-7a5nm4k9.css +1 -0
  128. package/dist/chunk-amb8y04y.js +1 -0
  129. package/dist/chunk-cf3pgy7j.js +546 -0
  130. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  131. package/dist/chunk-mzrgr577.js +5 -0
  132. package/dist/chunk-nf2wkvf9.js +14 -0
  133. package/dist/chunk-q6a0g26x.js +1 -0
  134. package/dist/chunk-twgdemkc.js +74 -0
  135. package/dist/chunk-x90k0f5c.js +2 -0
  136. package/dist/chunk-yq00csvd.js +2 -0
  137. package/dist/index.html +1 -1
  138. package/lib/app-icons.ts +1 -0
  139. package/lib/applet-selector.ts +24 -0
  140. package/lib/chat-title.ts +6 -1
  141. package/lib/default-widgets.ts +32 -0
  142. package/lib/format.ts +67 -7
  143. package/lib/message-attachments.ts +40 -0
  144. package/lib/moi-attachments.ts +204 -0
  145. package/lib/moi-context.ts +20 -35
  146. package/lib/navigation.ts +84 -0
  147. package/lib/themes.ts +6 -6
  148. package/lib/types.ts +91 -34
  149. package/lib/workspace-icon.ts +20 -0
  150. package/lib/workspace-layout.ts +22 -2
  151. package/lib/workspace-tabs.ts +9 -33
  152. package/package.json +42 -32
  153. package/registry.json +656 -0
  154. package/server/AGENTS.md +2 -0
  155. package/server/agent.ts +1 -1
  156. package/server/api.ts +139 -66
  157. package/server/applet-typecheck.ts +95 -0
  158. package/server/applets/applet-css.ts +55 -0
  159. package/server/{bundler → applets}/build-applet.ts +13 -242
  160. package/server/applets/build-worker.ts +178 -0
  161. package/server/applets/config.ts +226 -0
  162. package/server/applets/dependencies.ts +206 -0
  163. package/server/{applets.ts → applets/index.ts} +44 -189
  164. package/server/applets/runtime/base.ts +4 -0
  165. package/server/applets/runtime/moi.ts +42 -0
  166. package/server/applets/runtime/rpc.ts +17 -0
  167. package/server/applets/view-source.ts +67 -0
  168. package/server/attachment-message.ts +95 -0
  169. package/server/cli-ui-components.ts +28 -33
  170. package/server/cli.ts +169 -108
  171. package/server/control.ts +63 -42
  172. package/server/data-dir.ts +1 -1
  173. package/server/harness/README.md +45 -50
  174. package/server/harness/acp/NOTES.md +426 -0
  175. package/server/harness/acp/adapter.ts +7 -21
  176. package/server/harness/acp/discovery.ts +27 -30
  177. package/server/harness/acp/model-state.ts +57 -0
  178. package/server/harness/acp/session.ts +49 -56
  179. package/server/harness/claude-code/NOTES.md +54 -13
  180. package/server/harness/claude-code/adapter.ts +8 -25
  181. package/server/harness/claude-code/cli.ts +40 -0
  182. package/server/harness/claude-code/index.ts +13 -5
  183. package/server/harness/claude-code/models.ts +72 -19
  184. package/server/harness/claude-code/session.ts +447 -343
  185. package/server/harness/claude-code/sessions.ts +9 -4
  186. package/server/harness/codex/NOTES.md +222 -350
  187. package/server/harness/codex/adapter.ts +102 -52
  188. package/server/harness/codex/auth.ts +1 -3
  189. package/server/harness/codex/client.ts +169 -249
  190. package/server/harness/codex/discovery.ts +9 -17
  191. package/server/harness/codex/index.ts +3 -1
  192. package/server/harness/codex/pagination.ts +24 -0
  193. package/server/harness/codex/permissions.ts +32 -8
  194. package/server/harness/codex/probe.ts +10 -13
  195. package/server/harness/codex/session.ts +567 -181
  196. package/server/harness/codex/transport.ts +184 -0
  197. package/server/harness/debug.ts +1 -1
  198. package/server/harness/hermes/NOTES.md +19 -1
  199. package/server/harness/hermes/discovery.ts +20 -0
  200. package/server/harness/hermes/index.ts +13 -0
  201. package/server/harness/hermes/models.ts +28 -8
  202. package/server/harness/openclaw/NOTES.md +1 -1
  203. package/server/harness/openclaw/adapter.ts +22 -4
  204. package/server/harness/openclaw/gateway.ts +5 -3
  205. package/server/harness/openclaw/session.ts +27 -27
  206. package/server/harness/types.ts +9 -5
  207. package/server/layout.ts +9 -14
  208. package/server/moi-scaffold.ts +22 -14
  209. package/server/navigation-relay.ts +110 -0
  210. package/server/preview.ts +3 -1
  211. package/server/registry.ts +71 -41
  212. package/server/scratchpad-executor.ts +79 -56
  213. package/server/scratchpad-shape-defaults.ts +82 -0
  214. package/server/selected-session.ts +24 -4
  215. package/server/skill-update.ts +5 -3
  216. package/server/skill-version.ts +4 -7
  217. package/server/skills-template.ts +48 -9
  218. package/server/tabs.ts +19 -33
  219. package/server/tldraw-package.d.ts +4 -0
  220. package/server/ui-components.ts +101 -434
  221. package/server/uploads.ts +0 -0
  222. package/server/view-builders.ts +20 -2
  223. package/server/views.ts +126 -6
  224. package/server/web.ts +46 -13
  225. package/server/widgets.ts +12 -5
  226. package/server/workspace-config.ts +13 -9
  227. package/server/workspace-env.ts +3 -2
  228. package/tsconfig.json +0 -1
  229. package/ui-components/accordion.tsx +71 -0
  230. package/ui-components/alert-dialog.tsx +165 -0
  231. package/ui-components/alert.tsx +68 -0
  232. package/ui-components/attachment.tsx +195 -0
  233. package/ui-components/avatar.tsx +90 -0
  234. package/ui-components/badge.tsx +49 -0
  235. package/ui-components/button-group.tsx +78 -0
  236. package/ui-components/button.tsx +55 -0
  237. package/ui-components/calendar.tsx +180 -0
  238. package/ui-components/card.tsx +84 -0
  239. package/ui-components/carousel.tsx +235 -0
  240. package/ui-components/chart.tsx +338 -0
  241. package/ui-components/checkbox.tsx +28 -0
  242. package/ui-components/collapsible.tsx +15 -0
  243. package/ui-components/combobox.tsx +267 -0
  244. package/ui-components/context-menu.tsx +244 -0
  245. package/ui-components/dialog.tsx +138 -0
  246. package/ui-components/docs/accordion.md +463 -0
  247. package/ui-components/docs/alert-dialog.md +481 -0
  248. package/ui-components/docs/alert.md +301 -0
  249. package/ui-components/docs/attachment.md +689 -0
  250. package/ui-components/docs/avatar.md +495 -0
  251. package/ui-components/docs/badge.md +258 -0
  252. package/ui-components/docs/button-group.md +879 -0
  253. package/ui-components/docs/button.md +26 -0
  254. package/ui-components/docs/calendar.md +862 -0
  255. package/ui-components/docs/card.md +265 -0
  256. package/ui-components/docs/carousel.md +627 -0
  257. package/ui-components/docs/chart.md +1256 -0
  258. package/ui-components/docs/checkbox.md +477 -0
  259. package/ui-components/docs/collapsible.md +446 -0
  260. package/ui-components/docs/combobox.md +1003 -0
  261. package/ui-components/docs/context-menu.md +860 -0
  262. package/ui-components/docs/data-table.md +1580 -0
  263. package/ui-components/docs/date-picker.md +614 -0
  264. package/ui-components/docs/dialog.md +414 -0
  265. package/ui-components/docs/drawer.md +51 -0
  266. package/ui-components/docs/dropdown-menu.md +1000 -0
  267. package/ui-components/docs/field.md +1192 -0
  268. package/ui-components/docs/hover-card.md +275 -0
  269. package/ui-components/docs/input-group.md +866 -0
  270. package/ui-components/docs/input.md +456 -0
  271. package/ui-components/docs/kbd.md +191 -0
  272. package/ui-components/docs/label.md +295 -0
  273. package/ui-components/docs/pagination.md +416 -0
  274. package/ui-components/docs/popover.md +348 -0
  275. package/ui-components/docs/progress.md +214 -0
  276. package/ui-components/docs/radio-group.md +389 -0
  277. package/ui-components/docs/resizable.md +265 -0
  278. package/ui-components/docs/select.md +616 -0
  279. package/ui-components/docs/separator.md +216 -0
  280. package/ui-components/docs/skeleton.md +205 -0
  281. package/ui-components/docs/slider.md +226 -0
  282. package/ui-components/docs/spinner.md +332 -0
  283. package/ui-components/docs/switch.md +236 -0
  284. package/ui-components/docs/table.md +551 -0
  285. package/ui-components/docs/tabs.md +379 -0
  286. package/ui-components/docs/textarea.md +187 -0
  287. package/ui-components/docs/toggle-group.md +370 -0
  288. package/ui-components/docs/toggle.md +91 -0
  289. package/ui-components/docs/tooltip.md +290 -0
  290. package/ui-components/drawer.tsx +213 -0
  291. package/ui-components/dropdown-menu.tsx +263 -0
  292. package/ui-components/field.tsx +224 -0
  293. package/ui-components/hover-card.tsx +46 -0
  294. package/ui-components/input-group.tsx +146 -0
  295. package/ui-components/input.tsx +20 -0
  296. package/ui-components/kbd.tsx +32 -0
  297. package/ui-components/label.tsx +17 -0
  298. package/ui-components/pagination.tsx +124 -0
  299. package/ui-components/popover.tsx +81 -0
  300. package/ui-components/progress.tsx +63 -0
  301. package/ui-components/radio-group.tsx +38 -0
  302. package/ui-components/resizable.tsx +40 -0
  303. package/ui-components/scoped-portal.tsx +31 -0
  304. package/ui-components/select.tsx +195 -0
  305. package/ui-components/separator.tsx +18 -0
  306. package/ui-components/skeleton.tsx +15 -0
  307. package/ui-components/slider.tsx +75 -0
  308. package/ui-components/spinner.tsx +20 -0
  309. package/ui-components/switch.tsx +27 -0
  310. package/ui-components/table.tsx +86 -0
  311. package/ui-components/tabs.tsx +75 -0
  312. package/ui-components/textarea.tsx +17 -0
  313. package/ui-components/toggle-group.tsx +85 -0
  314. package/ui-components/toggle.tsx +42 -0
  315. package/ui-components/tooltip.tsx +61 -0
  316. package/ui-components/utils.ts +8 -0
  317. package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
  318. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
  319. package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
  320. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  321. package/client/features/chat/attachment-staging.ts +0 -153
  322. package/client/features/chat/uploads.ts +0 -18
  323. package/client/features/chat/useAppletChatMessage.ts +0 -68
  324. package/client/features/settings/IconPicker.tsx +0 -442
  325. package/client/features/settings/WorkspaceSettings.tsx +0 -92
  326. package/client/features/settings/render-icon.ts +0 -173
  327. package/client/features/widgets/HiddenPanel.tsx +0 -80
  328. package/client/features/widgets/WidgetGrid.tsx +0 -123
  329. package/client/features/widgets/Widgets.tsx +0 -264
  330. package/client/features/widgets/useGridReconcile.ts +0 -73
  331. package/dist/chunk-104m57qw.js +0 -2
  332. package/dist/chunk-59zf0m6n.js +0 -1
  333. package/dist/chunk-bj3akjs2.js +0 -1
  334. package/dist/chunk-c9pjqx9m.js +0 -14
  335. package/dist/chunk-j2w2vak4.js +0 -546
  336. package/dist/chunk-k2r9c95m.js +0 -10
  337. package/dist/chunk-kmbxhgwv.js +0 -1
  338. package/dist/chunk-p1yqa71k.js +0 -83
  339. package/dist/chunk-pcnahct1.js +0 -5
  340. package/dist/chunk-r5xrenjy.css +0 -1
  341. package/dist/chunk-tny85yt2.js +0 -2
  342. package/dist/chunk-v7wr1df4.js +0 -2
  343. package/server/bundler/applet-css.ts +0 -155
  344. /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
  345. /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
  346. /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
  347. /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
  348. /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
  349. /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
  350. /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
  351. /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
  352. /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
  353. /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
  354. /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
  355. /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
  356. /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
  357. /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
  358. /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
  359. /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
  360. /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
  361. /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
  362. /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
@@ -0,0 +1,1580 @@
1
+ ---
2
+ title: Data Table
3
+ description: Powerful table and datagrids built using TanStack Table.
4
+ base: base
5
+ component: true
6
+ links:
7
+ doc: https://tanstack.com/table/latest/docs/overview
8
+ ---
9
+
10
+ ```tsx
11
+ 'use client'
12
+
13
+ import * as React from 'react'
14
+ import {
15
+ columnFilteringFeature,
16
+ columnVisibilityFeature,
17
+ createColumnHelper,
18
+ createFilteredRowModel,
19
+ createPaginatedRowModel,
20
+ createSortedRowModel,
21
+ filterFn_includesString,
22
+ rowPaginationFeature,
23
+ rowSelectionFeature,
24
+ rowSortingFeature,
25
+ sortFn_alphanumeric,
26
+ sortFn_text,
27
+ tableFeatures,
28
+ useTable,
29
+ type ColumnFiltersState,
30
+ type ColumnVisibilityState,
31
+ type SortingState
32
+ } from '@tanstack/react-table'
33
+ import { IconArrowsUpDown, IconChevronDown, IconDots } from '@tabler/icons-react'
34
+
35
+ import { Button } from '@/components/ui/button'
36
+ import { Checkbox } from '@/components/ui/checkbox'
37
+ import {
38
+ DropdownMenu,
39
+ DropdownMenuCheckboxItem,
40
+ DropdownMenuContent,
41
+ DropdownMenuGroup,
42
+ DropdownMenuItem,
43
+ DropdownMenuLabel,
44
+ DropdownMenuSeparator,
45
+ DropdownMenuTrigger
46
+ } from '@/components/ui/dropdown-menu'
47
+ import { Input } from '@/components/ui/input'
48
+ import {
49
+ Table,
50
+ TableBody,
51
+ TableCell,
52
+ TableHead,
53
+ TableHeader,
54
+ TableRow
55
+ } from '@/components/ui/table'
56
+
57
+ // New in v9: declare the features this table uses — anything you don't
58
+ // register is tree-shaken out of the bundle.
59
+ const features = tableFeatures({
60
+ columnFilteringFeature,
61
+ columnVisibilityFeature,
62
+ rowPaginationFeature,
63
+ rowSelectionFeature,
64
+ rowSortingFeature,
65
+ filteredRowModel: createFilteredRowModel(),
66
+ paginatedRowModel: createPaginatedRowModel(),
67
+ sortedRowModel: createSortedRowModel(),
68
+ filterFns: { includesString: filterFn_includesString },
69
+ sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text }
70
+ })
71
+
72
+ const columnHelper = createColumnHelper<typeof features, Payment>()
73
+
74
+ const data: Payment[] = [
75
+ {
76
+ id: 'm5gr84i9',
77
+ amount: 316,
78
+ status: 'success',
79
+ email: 'ken99@example.com'
80
+ },
81
+ {
82
+ id: '3u1reuv4',
83
+ amount: 242,
84
+ status: 'success',
85
+ email: 'Abe45@example.com'
86
+ },
87
+ {
88
+ id: 'derv1ws0',
89
+ amount: 837,
90
+ status: 'processing',
91
+ email: 'Monserrat44@example.com'
92
+ },
93
+ {
94
+ id: '5kma53ae',
95
+ amount: 874,
96
+ status: 'success',
97
+ email: 'Silas22@example.com'
98
+ },
99
+ {
100
+ id: 'bhqecj4p',
101
+ amount: 721,
102
+ status: 'failed',
103
+ email: 'carmella@example.com'
104
+ }
105
+ ]
106
+
107
+ export type Payment = {
108
+ id: string
109
+ amount: number
110
+ status: 'pending' | 'processing' | 'success' | 'failed'
111
+ email: string
112
+ }
113
+
114
+ export const columns = columnHelper.columns([
115
+ columnHelper.display({
116
+ id: 'select',
117
+ header: ({ table }) => (
118
+ <Checkbox
119
+ checked={table.getIsAllPageRowsSelected()}
120
+ indeterminate={table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()}
121
+ onCheckedChange={value => table.toggleAllPageRowsSelected(!!value)}
122
+ aria-label="Select all"
123
+ />
124
+ ),
125
+ cell: ({ row }) => (
126
+ <Checkbox
127
+ checked={row.getIsSelected()}
128
+ onCheckedChange={value => row.toggleSelected(!!value)}
129
+ aria-label="Select row"
130
+ />
131
+ ),
132
+ enableSorting: false,
133
+ enableHiding: false
134
+ }),
135
+ columnHelper.accessor('status', {
136
+ header: 'Status',
137
+ cell: ({ row }) => <div className="capitalize">{row.getValue('status')}</div>
138
+ }),
139
+ columnHelper.accessor('email', {
140
+ header: ({ column }) => {
141
+ return (
142
+ <Button
143
+ variant="ghost"
144
+ onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
145
+ >
146
+ Email
147
+ <IconArrowsUpDown stroke={1.5} />
148
+ </Button>
149
+ )
150
+ },
151
+ cell: ({ row }) => <div className="lowercase">{row.getValue('email')}</div>
152
+ }),
153
+ columnHelper.accessor('amount', {
154
+ header: () => <div className="text-right">Amount</div>,
155
+ cell: ({ row }) => {
156
+ const amount = parseFloat(row.getValue('amount'))
157
+
158
+ // Format the amount as a dollar amount.
159
+ const formatted = new Intl.NumberFormat('en-US', {
160
+ style: 'currency',
161
+ currency: 'USD'
162
+ }).format(amount)
163
+
164
+ return <div className="text-right font-medium">{formatted}</div>
165
+ }
166
+ }),
167
+ columnHelper.display({
168
+ id: 'actions',
169
+ enableHiding: false,
170
+ cell: ({ row }) => {
171
+ const payment = row.original
172
+
173
+ return (
174
+ <DropdownMenu>
175
+ <DropdownMenuTrigger render={<Button variant="ghost" size="icon-xs" />}>
176
+ <span className="sr-only">Open menu</span>
177
+ <IconDots stroke={1.75} />
178
+ </DropdownMenuTrigger>
179
+ <DropdownMenuContent align="end" className="w-44">
180
+ <DropdownMenuGroup>
181
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
182
+ <DropdownMenuItem onClick={() => navigator.clipboard.writeText(payment.id)}>
183
+ Copy payment ID
184
+ </DropdownMenuItem>
185
+ </DropdownMenuGroup>
186
+ <DropdownMenuSeparator />
187
+ <DropdownMenuGroup>
188
+ <DropdownMenuItem>View customer</DropdownMenuItem>
189
+ <DropdownMenuItem>View payment details</DropdownMenuItem>
190
+ </DropdownMenuGroup>
191
+ </DropdownMenuContent>
192
+ </DropdownMenu>
193
+ )
194
+ }
195
+ })
196
+ ])
197
+
198
+ export function DataTableDemo() {
199
+ const [sorting, setSorting] = React.useState<SortingState>([])
200
+ const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
201
+ const [columnVisibility, setColumnVisibility] = React.useState<ColumnVisibilityState>({})
202
+ const [rowSelection, setRowSelection] = React.useState({})
203
+
204
+ const table = useTable({
205
+ features,
206
+ data,
207
+ columns,
208
+ onSortingChange: setSorting,
209
+ onColumnFiltersChange: setColumnFilters,
210
+ onColumnVisibilityChange: setColumnVisibility,
211
+ onRowSelectionChange: setRowSelection,
212
+ state: {
213
+ sorting,
214
+ columnFilters,
215
+ columnVisibility,
216
+ rowSelection
217
+ }
218
+ })
219
+
220
+ return (
221
+ <div className="w-full">
222
+ <div className="flex items-center py-4">
223
+ <Input
224
+ placeholder="Filter emails..."
225
+ value={(table.getColumn('email')?.getFilterValue() as string) ?? ''}
226
+ onChange={event => table.getColumn('email')?.setFilterValue(event.target.value)}
227
+ className="max-w-sm"
228
+ />
229
+ <DropdownMenu>
230
+ <DropdownMenuTrigger render={<Button variant="outline" className="ml-auto" />}>
231
+ Columns <IconChevronDown stroke={1.5} />
232
+ </DropdownMenuTrigger>
233
+ <DropdownMenuContent align="end" className="w-44">
234
+ <DropdownMenuGroup>
235
+ {table
236
+ .getAllColumns()
237
+ .filter(column => column.getCanHide())
238
+ .map(column => {
239
+ return (
240
+ <DropdownMenuCheckboxItem
241
+ key={column.id}
242
+ className="capitalize"
243
+ checked={column.getIsVisible()}
244
+ onCheckedChange={value => column.toggleVisibility(!!value)}
245
+ >
246
+ {column.id}
247
+ </DropdownMenuCheckboxItem>
248
+ )
249
+ })}
250
+ </DropdownMenuGroup>
251
+ </DropdownMenuContent>
252
+ </DropdownMenu>
253
+ </div>
254
+ <div className="overflow-hidden rounded-md border">
255
+ <Table>
256
+ <TableHeader>
257
+ {table.getHeaderGroups().map(headerGroup => (
258
+ <TableRow key={headerGroup.id}>
259
+ {headerGroup.headers.map(header => {
260
+ return (
261
+ <TableHead key={header.id}>
262
+ {header.isPlaceholder ? null : <table.FlexRender header={header} />}
263
+ </TableHead>
264
+ )
265
+ })}
266
+ </TableRow>
267
+ ))}
268
+ </TableHeader>
269
+ <TableBody>
270
+ {table.getRowModel().rows?.length ? (
271
+ table.getRowModel().rows.map(row => (
272
+ <TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
273
+ {row.getVisibleCells().map(cell => (
274
+ <TableCell key={cell.id}>
275
+ <table.FlexRender cell={cell} />
276
+ </TableCell>
277
+ ))}
278
+ </TableRow>
279
+ ))
280
+ ) : (
281
+ <TableRow>
282
+ <TableCell colSpan={columns.length} className="h-24 text-center">
283
+ No results.
284
+ </TableCell>
285
+ </TableRow>
286
+ )}
287
+ </TableBody>
288
+ </Table>
289
+ </div>
290
+ <div className="flex items-center justify-end space-x-2 py-4">
291
+ <div className="flex-1 text-sm text-muted-foreground">
292
+ {table.getFilteredSelectedRowModel().rows.length} of{' '}
293
+ {table.getFilteredRowModel().rows.length} row(s) selected.
294
+ </div>
295
+ <div className="space-x-2">
296
+ <Button
297
+ variant="outline"
298
+ size="sm"
299
+ onClick={() => table.previousPage()}
300
+ disabled={!table.getCanPreviousPage()}
301
+ >
302
+ Previous
303
+ </Button>
304
+ <Button
305
+ variant="outline"
306
+ size="sm"
307
+ onClick={() => table.nextPage()}
308
+ disabled={!table.getCanNextPage()}
309
+ >
310
+ Next
311
+ </Button>
312
+ </div>
313
+ </div>
314
+ </div>
315
+ )
316
+ }
317
+ ```
318
+
319
+ ## Introduction
320
+
321
+ Every data table or datagrid I've created has been unique. They all behave differently, have specific sorting and filtering requirements, and work with different data sources.
322
+
323
+ It doesn't make sense to combine all of these variations into a single component. If we do that, we'll lose the flexibility that [headless UI](https://tanstack.com/table/latest/docs/overview#what-is-headless-ui) provides.
324
+
325
+ So instead of a data-table component, I thought it would be more helpful to provide a guide on how to build your own.
326
+
327
+ We'll start with the basic `<Table />` component and build a complex data table from scratch.
328
+
329
+ <Callout className="mt-4">
330
+
331
+ **Tip:** If you find yourself using the same table in multiple places in your app, you can always extract it into a reusable component.
332
+
333
+ </Callout>
334
+
335
+ ## Table of Contents
336
+
337
+ This guide will show you how to use [TanStack Table](https://tanstack.com/table) and the `<Table />` component to build your own custom data table. We'll cover the following topics:
338
+
339
+ - [Set up Table Features](#set-up-table-features)
340
+ - [Basic Table](#basic-table)
341
+ - [Row Actions](#row-actions)
342
+ - [Pagination](#pagination)
343
+ - [Sorting](#sorting)
344
+ - [Filtering](#filtering)
345
+ - [Visibility](#visibility)
346
+ - [Row Selection](#row-selection)
347
+ - [Reusable Components](#reusable-components)
348
+
349
+ ## Installation
350
+
351
+ 1. Add the `<Table />` component to your project:
352
+
353
+ ```bash
354
+ moi ui-components add data-table
355
+ ```
356
+
357
+ 2. Add the `@tanstack/react-table` dependency. This guide uses **TanStack Table v9**:
358
+
359
+ ```bash
360
+ npm install @tanstack/react-table
361
+ ```
362
+
363
+ ## Prerequisites
364
+
365
+ We are going to build a table to show recent payments. Here's what our data looks like:
366
+
367
+ ```tsx showLineNumbers
368
+ type Payment = {
369
+ id: string
370
+ amount: number
371
+ status: 'pending' | 'processing' | 'success' | 'failed'
372
+ email: string
373
+ }
374
+
375
+ export const payments: Payment[] = [
376
+ {
377
+ id: '728ed52f',
378
+ amount: 100,
379
+ status: 'pending',
380
+ email: 'm@example.com'
381
+ },
382
+ {
383
+ id: '489e1d42',
384
+ amount: 125,
385
+ status: 'processing',
386
+ email: 'example@gmail.com'
387
+ }
388
+ // ...
389
+ ]
390
+ ```
391
+
392
+ ## Project Structure
393
+
394
+ Start by creating the following file structure:
395
+
396
+ ```txt
397
+ app
398
+ └── payments
399
+ ├── columns.tsx
400
+ ├── data-table-features.ts
401
+ ├── data-table.tsx
402
+ └── page.tsx
403
+ ```
404
+
405
+ I'm using a Next.js example here but this works for any other React framework.
406
+
407
+ - `columns.tsx` (client component) will contain our column definitions.
408
+ - `data-table-features.ts` will contain the shared `features` object that tells TanStack Table which behavior to enable.
409
+ - `data-table.tsx` (client component) will contain our `<DataTable />` component.
410
+ - `page.tsx` (server component) is where we'll fetch data and render our table.
411
+
412
+ ## Set up Table Features
413
+
414
+ TanStack Table v9 is feature-based: you opt into the behavior you want — sorting, filtering, pagination, and so on — by declaring it with `tableFeatures()`. Anything you don't list is tree-shaken out of your bundle. That includes the built-in filter and sort functions: register the ones your columns rely on under `filterFns` and `sortFns` (our email filter uses `includesString`, and string columns sort with `text` / `alphanumeric`).
415
+
416
+ ```tsx showLineNumbers title="app/payments/data-table-features.ts"
417
+ import {
418
+ columnFilteringFeature,
419
+ columnVisibilityFeature,
420
+ createFilteredRowModel,
421
+ createPaginatedRowModel,
422
+ createSortedRowModel,
423
+ filterFn_includesString,
424
+ rowPaginationFeature,
425
+ rowSelectionFeature,
426
+ rowSortingFeature,
427
+ sortFn_alphanumeric,
428
+ sortFn_text,
429
+ tableFeatures
430
+ } from '@tanstack/react-table'
431
+
432
+ // New in v9: declare the features this table uses — anything you don't
433
+ // register is tree-shaken out of the bundle.
434
+ export const features = tableFeatures({
435
+ columnFilteringFeature,
436
+ columnVisibilityFeature,
437
+ rowPaginationFeature,
438
+ rowSelectionFeature,
439
+ rowSortingFeature,
440
+ filteredRowModel: createFilteredRowModel(),
441
+ paginatedRowModel: createPaginatedRowModel(),
442
+ sortedRowModel: createSortedRowModel(),
443
+ filterFns: { includesString: filterFn_includesString },
444
+ sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text }
445
+ })
446
+
447
+ // Pass this as the first generic argument to `ColumnDef`, `Column`, `Table`,
448
+ // and `Row` so each type knows which feature APIs are available.
449
+ export type DataTableFeatures = typeof features
450
+ ```
451
+
452
+ <Callout className="mt-4">
453
+
454
+ **Note:** The core row model is always included, so you never register it yourself. Row models for optional features are created with `create*RowModel()` and registered on the features object — there are no more `get*RowModel` table options.
455
+
456
+ </Callout>
457
+
458
+ ## Basic Table
459
+
460
+ Let's start by building a basic table.
461
+
462
+ <Steps className="mb-0 pt-2">
463
+
464
+ ### Column Definitions
465
+
466
+ First, we'll define our columns.
467
+
468
+ ```tsx showLineNumbers title="app/payments/columns.tsx" {3,5,16-17,19-29}
469
+ 'use client'
470
+
471
+ import { createColumnHelper } from '@tanstack/react-table'
472
+
473
+ import { type DataTableFeatures } from './data-table-features'
474
+
475
+ // This type is used to define the shape of our data.
476
+ // You can use a Zod schema here if you want.
477
+ export type Payment = {
478
+ id: string
479
+ amount: number
480
+ status: 'pending' | 'processing' | 'success' | 'failed'
481
+ email: string
482
+ }
483
+
484
+ // Use `accessor` for data columns and `display` for columns without one.
485
+ const columnHelper = createColumnHelper<DataTableFeatures, Payment>()
486
+
487
+ export const columns = columnHelper.columns([
488
+ columnHelper.accessor('status', {
489
+ header: 'Status'
490
+ }),
491
+ columnHelper.accessor('email', {
492
+ header: 'Email'
493
+ }),
494
+ columnHelper.accessor('amount', {
495
+ header: 'Amount'
496
+ })
497
+ ])
498
+ ```
499
+
500
+ <Callout className="mt-4">
501
+
502
+ **Note:** Columns are where you define the core of what your table
503
+ will look like. They define the data that will be displayed, how it will be
504
+ formatted, sorted and filtered.
505
+
506
+ </Callout>
507
+
508
+ ### `<DataTable />` component
509
+
510
+ Next, we'll create a `<DataTable />` component to render our table.
511
+
512
+ ```tsx showLineNumbers title="app/payments/data-table.tsx"
513
+ 'use client'
514
+
515
+ import { useTable, type ColumnDef, type RowData } from '@tanstack/react-table'
516
+
517
+ import {
518
+ Table,
519
+ TableBody,
520
+ TableCell,
521
+ TableHead,
522
+ TableHeader,
523
+ TableRow
524
+ } from '@/components/ui/table'
525
+
526
+ import { features, type DataTableFeatures } from './data-table-features'
527
+
528
+ interface DataTableProps<TData extends RowData> {
529
+ columns: ColumnDef<DataTableFeatures, TData>[]
530
+ data: TData[]
531
+ }
532
+
533
+ export function DataTable<TData extends RowData>({ columns, data }: DataTableProps<TData>) {
534
+ const table = useTable({
535
+ features,
536
+ data,
537
+ columns
538
+ })
539
+
540
+ return (
541
+ <div className="overflow-hidden rounded-md border">
542
+ <Table>
543
+ <TableHeader>
544
+ {table.getHeaderGroups().map(headerGroup => (
545
+ <TableRow key={headerGroup.id}>
546
+ {headerGroup.headers.map(header => {
547
+ return (
548
+ <TableHead key={header.id}>
549
+ {header.isPlaceholder ? null : <table.FlexRender header={header} />}
550
+ </TableHead>
551
+ )
552
+ })}
553
+ </TableRow>
554
+ ))}
555
+ </TableHeader>
556
+ <TableBody>
557
+ {table.getRowModel().rows?.length ? (
558
+ table.getRowModel().rows.map(row => (
559
+ <TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
560
+ {row.getVisibleCells().map(cell => (
561
+ <TableCell key={cell.id}>
562
+ <table.FlexRender cell={cell} />
563
+ </TableCell>
564
+ ))}
565
+ </TableRow>
566
+ ))
567
+ ) : (
568
+ <TableRow>
569
+ <TableCell colSpan={columns.length} className="h-24 text-center">
570
+ No results.
571
+ </TableCell>
572
+ </TableRow>
573
+ )}
574
+ </TableBody>
575
+ </Table>
576
+ </div>
577
+ )
578
+ }
579
+ ```
580
+
581
+ <Callout>
582
+
583
+ **Tip**: If you find yourself using `<DataTable />` in multiple places, this is the component you could make reusable by extracting it to `components/ui/data-table.tsx`.
584
+
585
+ `<DataTable columns={columns} data={data} />`
586
+
587
+ </Callout>
588
+
589
+ <Callout className="mt-4">
590
+
591
+ **`<table.FlexRender />` vs `flexRender`:** This guide uses v9's `<table.FlexRender header={header} />` and `<table.FlexRender cell={cell} />` component, available right on the table instance — no extra import needed. The classic `flexRender(component, context)` helper from v8 still works too, if you prefer the function form (or need to render outside the component that owns `table`, where you can also import the standalone `<FlexRender />`).
592
+
593
+ </Callout>
594
+
595
+ ### Render the table
596
+
597
+ Finally, we'll render our table in our page component.
598
+
599
+ ```tsx showLineNumbers title="app/payments/page.tsx" {22}
600
+ import { columns, Payment } from './columns'
601
+ import { DataTable } from './data-table'
602
+
603
+ async function getData(): Promise<Payment[]> {
604
+ // Fetch data from your API here.
605
+ return [
606
+ {
607
+ id: '728ed52f',
608
+ amount: 100,
609
+ status: 'pending',
610
+ email: 'm@example.com'
611
+ }
612
+ // ...
613
+ ]
614
+ }
615
+
616
+ export default async function DemoPage() {
617
+ const data = await getData()
618
+
619
+ return (
620
+ <div className="container mx-auto py-10">
621
+ <DataTable columns={columns} data={data} />
622
+ </div>
623
+ )
624
+ }
625
+ ```
626
+
627
+ </Steps>
628
+
629
+ ## Cell Formatting
630
+
631
+ Let's format the amount cell to display the dollar amount. We'll also align the cell to the right.
632
+
633
+ <Steps className="mb-0 pt-2">
634
+
635
+ ### Update columns definition
636
+
637
+ Update the `header` and `cell` definitions for amount as follows:
638
+
639
+ ```tsx showLineNumbers title="app/payments/columns.tsx" {3-13}
640
+ export const columns = columnHelper.columns([
641
+ columnHelper.accessor('amount', {
642
+ header: () => <div className="text-right">Amount</div>,
643
+ cell: ({ row }) => {
644
+ const amount = parseFloat(row.getValue('amount'))
645
+ const formatted = new Intl.NumberFormat('en-US', {
646
+ style: 'currency',
647
+ currency: 'USD'
648
+ }).format(amount)
649
+
650
+ return <div className="text-right font-medium">{formatted}</div>
651
+ }
652
+ })
653
+ ])
654
+ ```
655
+
656
+ You can use the same approach to format other cells and headers.
657
+
658
+ </Steps>
659
+
660
+ ## Row Actions
661
+
662
+ Let's add row actions to our table. We'll use a `<DropdownMenu />` component for this.
663
+
664
+ <Steps className="mb-0 pt-2">
665
+
666
+ ### Update columns definition
667
+
668
+ Update our columns definition to add a new `actions` column. The `actions` cell returns a `<DropdownMenu />` component.
669
+
670
+ ```tsx showLineNumbers title="app/payments/columns.tsx" {4,6-14,18-45}
671
+ 'use client'
672
+
673
+ import { createColumnHelper } from '@tanstack/react-table'
674
+ import { IconDots } from '@tabler/icons-react'
675
+
676
+ import { Button } from '@/components/ui/button'
677
+ import {
678
+ DropdownMenu,
679
+ DropdownMenuContent,
680
+ DropdownMenuItem,
681
+ DropdownMenuLabel,
682
+ DropdownMenuSeparator,
683
+ DropdownMenuTrigger
684
+ } from '@/components/ui/dropdown-menu'
685
+
686
+ export const columns = columnHelper.columns([
687
+ // ...
688
+ columnHelper.display({
689
+ id: 'actions',
690
+ cell: ({ row }) => {
691
+ const payment = row.original
692
+
693
+ return (
694
+ <DropdownMenu>
695
+ <DropdownMenuTrigger render={<Button variant="ghost" className="h-8 w-8 p-0" />}>
696
+ <span className="sr-only">Open menu</span>
697
+ <IconDots stroke={1.5} className="h-4 w-4" />
698
+ </DropdownMenuTrigger>
699
+ <DropdownMenuContent align="end">
700
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
701
+ <DropdownMenuItem onClick={() => navigator.clipboard.writeText(payment.id)}>
702
+ Copy payment ID
703
+ </DropdownMenuItem>
704
+ <DropdownMenuSeparator />
705
+ <DropdownMenuItem>View customer</DropdownMenuItem>
706
+ <DropdownMenuItem>View payment details</DropdownMenuItem>
707
+ </DropdownMenuContent>
708
+ </DropdownMenu>
709
+ )
710
+ }
711
+ })
712
+ // ...
713
+ ])
714
+ ```
715
+
716
+ You can access the row data using `row.original` in the `cell` function. Use this to handle actions for your row eg. use the `id` to make a DELETE call to your API.
717
+
718
+ </Steps>
719
+
720
+ ## Pagination
721
+
722
+ Next, we'll add pagination to our table.
723
+
724
+ <Steps className="mb-0 pt-2">
725
+
726
+ ### Pagination is already enabled
727
+
728
+ Because our features object includes `rowPaginationFeature` and `createPaginatedRowModel()`, the table automatically paginates rows into pages of 10 — there's nothing to add to `useTable`. See the [pagination docs](https://tanstack.com/table/latest/docs/framework/react/guide/pagination) for more information on customizing page size and implementing manual pagination.
729
+
730
+ ### Add pagination controls
731
+
732
+ We can add pagination controls to our table using the `<Button />` component and the `table.previousPage()`, `table.nextPage()` API methods.
733
+
734
+ ```tsx showLineNumbers title="app/payments/data-table.tsx" {1,20-37}
735
+ import { Button } from "@/components/ui/button"
736
+
737
+ export function DataTable<TData extends RowData>({
738
+ columns,
739
+ data,
740
+ }: DataTableProps<TData>) {
741
+ const table = useTable({
742
+ features,
743
+ data,
744
+ columns,
745
+ })
746
+
747
+ return (
748
+ <div>
749
+ <div className="overflow-hidden rounded-md border">
750
+ <Table>
751
+ { // .... }
752
+ </Table>
753
+ </div>
754
+ <div className="flex items-center justify-end space-x-2 py-4">
755
+ <Button
756
+ variant="outline"
757
+ size="sm"
758
+ onClick={() => table.previousPage()}
759
+ disabled={!table.getCanPreviousPage()}
760
+ >
761
+ Previous
762
+ </Button>
763
+ <Button
764
+ variant="outline"
765
+ size="sm"
766
+ onClick={() => table.nextPage()}
767
+ disabled={!table.getCanNextPage()}
768
+ >
769
+ Next
770
+ </Button>
771
+ </div>
772
+ </div>
773
+ )
774
+ }
775
+ ```
776
+
777
+ See [Reusable Components](#reusable-components) section for a more advanced pagination component.
778
+
779
+ </Steps>
780
+
781
+ ## Sorting
782
+
783
+ Let's make the email column sortable.
784
+
785
+ The `rowSortingFeature` and sorted row model are already registered in our features object, so all that's left is wiring up the sorting state.
786
+
787
+ <Steps className="mb-0 pt-2">
788
+
789
+ ### Update `<DataTable>`
790
+
791
+ ```tsx showLineNumbers title="app/payments/data-table.tsx" {3,8,15,21-24}
792
+ "use client"
793
+
794
+ import * as React from "react"
795
+ import {
796
+ useTable,
797
+ type ColumnDef,
798
+ type RowData,
799
+ type SortingState,
800
+ } from "@tanstack/react-table"
801
+
802
+ export function DataTable<TData extends RowData>({
803
+ columns,
804
+ data,
805
+ }: DataTableProps<TData>) {
806
+ const [sorting, setSorting] = React.useState<SortingState>([])
807
+
808
+ const table = useTable({
809
+ features,
810
+ data,
811
+ columns,
812
+ onSortingChange: setSorting,
813
+ state: {
814
+ sorting,
815
+ },
816
+ })
817
+
818
+ return (
819
+ <div>
820
+ <div className="overflow-hidden rounded-md border">
821
+ <Table>{ ... }</Table>
822
+ </div>
823
+ </div>
824
+ )
825
+ }
826
+ ```
827
+
828
+ ### Make header cell sortable
829
+
830
+ We can now update the `email` header cell to add sorting controls.
831
+
832
+ ```tsx showLineNumbers title="app/payments/columns.tsx" {4,8-18}
833
+ 'use client'
834
+
835
+ import { createColumnHelper } from '@tanstack/react-table'
836
+ import { IconArrowsUpDown } from '@tabler/icons-react'
837
+
838
+ export const columns = columnHelper.columns([
839
+ columnHelper.accessor('email', {
840
+ header: ({ column }) => {
841
+ return (
842
+ <Button
843
+ variant="ghost"
844
+ onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
845
+ >
846
+ Email
847
+ <IconArrowsUpDown stroke={1.5} className="ml-2 h-4 w-4" />
848
+ </Button>
849
+ )
850
+ }
851
+ })
852
+ ])
853
+ ```
854
+
855
+ This will automatically sort the table (asc and desc) when the user toggles on the header cell.
856
+
857
+ </Steps>
858
+
859
+ ## Filtering
860
+
861
+ Let's add a search input to filter emails in our table.
862
+
863
+ The `columnFilteringFeature` and filtered row model are already part of our features object, so we only need to wire up the filter state and render an input.
864
+
865
+ <Steps className="mb-0 pt-2">
866
+
867
+ ### Update `<DataTable>`
868
+
869
+ ```tsx showLineNumbers title="app/payments/data-table.tsx" {7,13,20-22,29,32,38-46}
870
+ "use client"
871
+
872
+ import * as React from "react"
873
+ import {
874
+ useTable,
875
+ type ColumnDef,
876
+ type ColumnFiltersState,
877
+ type RowData,
878
+ type SortingState,
879
+ } from "@tanstack/react-table"
880
+
881
+ import { Button } from "@/components/ui/button"
882
+ import { Input } from "@/components/ui/input"
883
+
884
+ export function DataTable<TData extends RowData>({
885
+ columns,
886
+ data,
887
+ }: DataTableProps<TData>) {
888
+ const [sorting, setSorting] = React.useState<SortingState>([])
889
+ const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
890
+ []
891
+ )
892
+
893
+ const table = useTable({
894
+ features,
895
+ data,
896
+ columns,
897
+ onSortingChange: setSorting,
898
+ onColumnFiltersChange: setColumnFilters,
899
+ state: {
900
+ sorting,
901
+ columnFilters,
902
+ },
903
+ })
904
+
905
+ return (
906
+ <div>
907
+ <div className="flex items-center py-4">
908
+ <Input
909
+ placeholder="Filter emails..."
910
+ value={(table.getColumn("email")?.getFilterValue() as string) ?? ""}
911
+ onChange={(event) =>
912
+ table.getColumn("email")?.setFilterValue(event.target.value)
913
+ }
914
+ className="max-w-sm"
915
+ />
916
+ </div>
917
+ <div className="overflow-hidden rounded-md border">
918
+ <Table>{ ... }</Table>
919
+ </div>
920
+ </div>
921
+ )
922
+ }
923
+ ```
924
+
925
+ Filtering is now enabled for the `email` column. You can add filters to other columns as well. See the [filtering docs](https://tanstack.com/table/latest/docs/framework/react/guide/column-filtering) for more information on customizing filters.
926
+
927
+ </Steps>
928
+
929
+ ## Visibility
930
+
931
+ Adding column visibility is fairly simple using `@tanstack/react-table` visibility API.
932
+
933
+ <Steps className="mb-0 pt-2">
934
+
935
+ ### Update `<DataTable>`
936
+
937
+ ```tsx showLineNumbers title="app/payments/data-table.tsx" {8,14-19,29-30,38,42,57-84}
938
+ "use client"
939
+
940
+ import * as React from "react"
941
+ import {
942
+ useTable,
943
+ type ColumnDef,
944
+ type ColumnFiltersState,
945
+ type ColumnVisibilityState,
946
+ type RowData,
947
+ type SortingState,
948
+ } from "@tanstack/react-table"
949
+
950
+ import { Button } from "@/components/ui/button"
951
+ import {
952
+ DropdownMenu,
953
+ DropdownMenuCheckboxItem,
954
+ DropdownMenuContent,
955
+ DropdownMenuTrigger,
956
+ } from "@/components/ui/dropdown-menu"
957
+
958
+ export function DataTable<TData extends RowData>({
959
+ columns,
960
+ data,
961
+ }: DataTableProps<TData>) {
962
+ const [sorting, setSorting] = React.useState<SortingState>([])
963
+ const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
964
+ []
965
+ )
966
+ const [columnVisibility, setColumnVisibility] =
967
+ React.useState<ColumnVisibilityState>({})
968
+
969
+ const table = useTable({
970
+ features,
971
+ data,
972
+ columns,
973
+ onSortingChange: setSorting,
974
+ onColumnFiltersChange: setColumnFilters,
975
+ onColumnVisibilityChange: setColumnVisibility,
976
+ state: {
977
+ sorting,
978
+ columnFilters,
979
+ columnVisibility,
980
+ },
981
+ })
982
+
983
+ return (
984
+ <div>
985
+ <div className="flex items-center py-4">
986
+ <Input
987
+ placeholder="Filter emails..."
988
+ value={table.getColumn("email")?.getFilterValue() as string}
989
+ onChange={(event) =>
990
+ table.getColumn("email")?.setFilterValue(event.target.value)
991
+ }
992
+ className="max-w-sm"
993
+ />
994
+ <DropdownMenu>
995
+ <DropdownMenuTrigger render={<Button variant="outline" className="ml-auto" />}>
996
+ Columns
997
+ </DropdownMenuTrigger>
998
+ <DropdownMenuContent align="end">
999
+ {table
1000
+ .getAllColumns()
1001
+ .filter(
1002
+ (column) => column.getCanHide()
1003
+ )
1004
+ .map((column) => {
1005
+ return (
1006
+ <DropdownMenuCheckboxItem
1007
+ key={column.id}
1008
+ className="capitalize"
1009
+ checked={column.getIsVisible()}
1010
+ onCheckedChange={(value) =>
1011
+ column.toggleVisibility(!!value)
1012
+ }
1013
+ >
1014
+ {column.id}
1015
+ </DropdownMenuCheckboxItem>
1016
+ )
1017
+ })}
1018
+ </DropdownMenuContent>
1019
+ </DropdownMenu>
1020
+ </div>
1021
+ <div className="overflow-hidden rounded-md border">
1022
+ <Table>{ ... }</Table>
1023
+ </div>
1024
+ </div>
1025
+ )
1026
+ }
1027
+ ```
1028
+
1029
+ This adds a dropdown menu that you can use to toggle column visibility.
1030
+
1031
+ </Steps>
1032
+
1033
+ ## Row Selection
1034
+
1035
+ Next, we're going to add row selection to our table.
1036
+
1037
+ <Steps className="mb-0 pt-2">
1038
+
1039
+ ### Update column definitions
1040
+
1041
+ ```tsx showLineNumbers title="app/payments/columns.tsx" {6,9-30}
1042
+ 'use client'
1043
+
1044
+ import { createColumnHelper } from '@tanstack/react-table'
1045
+
1046
+ import { Badge } from '@/components/ui/badge'
1047
+ import { Checkbox } from '@/components/ui/checkbox'
1048
+
1049
+ export const columns = columnHelper.columns([
1050
+ columnHelper.display({
1051
+ id: 'select',
1052
+ header: ({ table }) => (
1053
+ <Checkbox
1054
+ checked={table.getIsAllPageRowsSelected()}
1055
+ indeterminate={table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()}
1056
+ onCheckedChange={value => table.toggleAllPageRowsSelected(!!value)}
1057
+ aria-label="Select all"
1058
+ />
1059
+ ),
1060
+ cell: ({ row }) => (
1061
+ <Checkbox
1062
+ checked={row.getIsSelected()}
1063
+ onCheckedChange={value => row.toggleSelected(!!value)}
1064
+ aria-label="Select row"
1065
+ />
1066
+ ),
1067
+ enableSorting: false,
1068
+ enableHiding: false
1069
+ })
1070
+ ])
1071
+ ```
1072
+
1073
+ ### Update `<DataTable>`
1074
+
1075
+ ```tsx showLineNumbers title="app/payments/data-table.tsx" {11,20,25}
1076
+ export function DataTable<TData extends RowData>({ columns, data }: DataTableProps<TData>) {
1077
+ const [sorting, setSorting] = React.useState<SortingState>([])
1078
+ const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
1079
+ const [columnVisibility, setColumnVisibility] = React.useState<ColumnVisibilityState>({})
1080
+ const [rowSelection, setRowSelection] = React.useState({})
1081
+
1082
+ const table = useTable({
1083
+ features,
1084
+ data,
1085
+ columns,
1086
+ onSortingChange: setSorting,
1087
+ onColumnFiltersChange: setColumnFilters,
1088
+ onColumnVisibilityChange: setColumnVisibility,
1089
+ onRowSelectionChange: setRowSelection,
1090
+ state: {
1091
+ sorting,
1092
+ columnFilters,
1093
+ columnVisibility,
1094
+ rowSelection
1095
+ }
1096
+ })
1097
+
1098
+ return (
1099
+ <div>
1100
+ <div className="overflow-hidden rounded-md border">
1101
+ <Table />
1102
+ </div>
1103
+ </div>
1104
+ )
1105
+ }
1106
+ ```
1107
+
1108
+ This adds a checkbox to each row and a checkbox in the header to select all rows.
1109
+
1110
+ ### Show selected rows
1111
+
1112
+ You can show the number of selected rows using the `table.getFilteredSelectedRowModel()` API.
1113
+
1114
+ ```tsx
1115
+ <div className="flex-1 text-sm text-muted-foreground">
1116
+ {table.getFilteredSelectedRowModel().rows.length} of {table.getFilteredRowModel().rows.length}{' '}
1117
+ row(s) selected.
1118
+ </div>
1119
+ ```
1120
+
1121
+ </Steps>
1122
+
1123
+ ## Reusable Components
1124
+
1125
+ Here are some components you can use to build your data tables. This is from the [Tasks](/examples/tasks) demo, which shares its features object (and the matching `TasksTableFeatures` type) across every component via a `data-table-features.ts` module — the same pattern we set up in [Set up Table Features](#set-up-table-features).
1126
+
1127
+ ### Column header
1128
+
1129
+ Make any column header sortable and hideable.
1130
+
1131
+ <ComponentSource
1132
+ src="/app/(app)/examples/tasks/components/data-table-column-header.tsx"
1133
+ title="components/data-table-column-header.tsx"
1134
+ />
1135
+
1136
+ ```tsx showLineNumbers {4}
1137
+ export const columns = columnHelper.columns([
1138
+ columnHelper.accessor('email', {
1139
+ header: ({ column }) => <DataTableColumnHeader column={column} title="Email" />
1140
+ })
1141
+ ])
1142
+ ```
1143
+
1144
+ ### Pagination
1145
+
1146
+ Add pagination controls to your table including page size and selection count.
1147
+
1148
+ <ComponentSource
1149
+ src="/app/(app)/examples/tasks/components/data-table-pagination.tsx"
1150
+ styleName="radix-nova"
1151
+ />
1152
+
1153
+ ```tsx
1154
+ <DataTablePagination table={table} />
1155
+ ```
1156
+
1157
+ ### Column toggle
1158
+
1159
+ A component to toggle column visibility.
1160
+
1161
+ <ComponentSource
1162
+ src="/app/(app)/examples/tasks/components/data-table-view-options.tsx"
1163
+ styleName="radix-nova"
1164
+ />
1165
+
1166
+ ```tsx
1167
+ <DataTableViewOptions table={table} />
1168
+ ```
1169
+
1170
+ ## RTL
1171
+
1172
+ ```tsx
1173
+ 'use client'
1174
+
1175
+ import * as React from 'react'
1176
+ import {
1177
+ columnFilteringFeature,
1178
+ columnVisibilityFeature,
1179
+ createColumnHelper,
1180
+ createFilteredRowModel,
1181
+ createPaginatedRowModel,
1182
+ createSortedRowModel,
1183
+ filterFn_includesString,
1184
+ rowPaginationFeature,
1185
+ rowSelectionFeature,
1186
+ rowSortingFeature,
1187
+ sortFn_alphanumeric,
1188
+ sortFn_text,
1189
+ tableFeatures,
1190
+ useTable,
1191
+ type ColumnFiltersState,
1192
+ type ColumnVisibilityState,
1193
+ type SortingState
1194
+ } from '@tanstack/react-table'
1195
+ import { IconArrowsUpDown, IconChevronDown, IconDots } from '@tabler/icons-react'
1196
+
1197
+ import { useTranslation, type Translations } from '@/components/language-selector'
1198
+ import { Button } from '@/components/ui/button'
1199
+ import { Checkbox } from '@/components/ui/checkbox'
1200
+ import {
1201
+ DropdownMenu,
1202
+ DropdownMenuCheckboxItem,
1203
+ DropdownMenuContent,
1204
+ DropdownMenuGroup,
1205
+ DropdownMenuItem,
1206
+ DropdownMenuLabel,
1207
+ DropdownMenuSeparator,
1208
+ DropdownMenuTrigger
1209
+ } from '@/components/ui/dropdown-menu'
1210
+ import { Input } from '@/components/ui/input'
1211
+ import {
1212
+ Table,
1213
+ TableBody,
1214
+ TableCell,
1215
+ TableHead,
1216
+ TableHeader,
1217
+ TableRow
1218
+ } from '@/components/ui/table'
1219
+
1220
+ const translations: Translations = {
1221
+ en: {
1222
+ dir: 'ltr',
1223
+ values: {
1224
+ filterEmails: 'Filter emails...',
1225
+ columns: 'Columns',
1226
+ status: 'Status',
1227
+ email: 'Email',
1228
+ amount: 'Amount',
1229
+ actions: 'Actions',
1230
+ copyPaymentId: 'Copy payment ID',
1231
+ viewCustomer: 'View customer',
1232
+ viewPaymentDetails: 'View payment details',
1233
+ selectAll: 'Select all',
1234
+ selectRow: 'Select row',
1235
+ openMenu: 'Open menu',
1236
+ noResults: 'No results.',
1237
+ rowsSelected: 'of',
1238
+ rowsSelectedSuffix: 'row(s) selected.',
1239
+ previous: 'Previous',
1240
+ next: 'Next',
1241
+ success: 'Success',
1242
+ processing: 'Processing',
1243
+ failed: 'Failed',
1244
+ pending: 'Pending'
1245
+ }
1246
+ },
1247
+ ar: {
1248
+ dir: 'rtl',
1249
+ values: {
1250
+ filterEmails: 'تصفية البريد الإلكتروني...',
1251
+ columns: 'الأعمدة',
1252
+ status: 'الحالة',
1253
+ email: 'البريد الإلكتروني',
1254
+ amount: 'المبلغ',
1255
+ actions: 'الإجراءات',
1256
+ copyPaymentId: 'نسخ معرف الدفع',
1257
+ viewCustomer: 'عرض العميل',
1258
+ viewPaymentDetails: 'عرض تفاصيل الدفع',
1259
+ selectAll: 'تحديد الكل',
1260
+ selectRow: 'تحديد الصف',
1261
+ openMenu: 'فتح القائمة',
1262
+ noResults: 'لا توجد نتائج.',
1263
+ rowsSelected: 'من',
1264
+ rowsSelectedSuffix: 'صف(وف) محدد.',
1265
+ previous: 'السابق',
1266
+ next: 'التالي',
1267
+ success: 'ناجح',
1268
+ processing: 'قيد المعالجة',
1269
+ failed: 'فشل',
1270
+ pending: 'قيد الانتظار'
1271
+ }
1272
+ },
1273
+ he: {
1274
+ dir: 'rtl',
1275
+ values: {
1276
+ filterEmails: 'סנן אימיילים...',
1277
+ columns: 'עמודות',
1278
+ status: 'סטטוס',
1279
+ email: 'אימייל',
1280
+ amount: 'סכום',
1281
+ actions: 'פעולות',
1282
+ copyPaymentId: 'העתק מזהה תשלום',
1283
+ viewCustomer: 'צפה בלקוח',
1284
+ viewPaymentDetails: 'צפה בפרטי תשלום',
1285
+ selectAll: 'בחר הכל',
1286
+ selectRow: 'בחר שורה',
1287
+ openMenu: 'פתח תפריט',
1288
+ noResults: 'אין תוצאות.',
1289
+ rowsSelected: 'מתוך',
1290
+ rowsSelectedSuffix: 'שורות נבחרו.',
1291
+ previous: 'הקודם',
1292
+ next: 'הבא',
1293
+ success: 'הצליח',
1294
+ processing: 'מעבד',
1295
+ failed: 'נכשל',
1296
+ pending: 'ממתין'
1297
+ }
1298
+ }
1299
+ }
1300
+
1301
+ // New in v9: declare the features this table uses — anything you don't
1302
+ // register is tree-shaken out of the bundle.
1303
+ const features = tableFeatures({
1304
+ columnFilteringFeature,
1305
+ columnVisibilityFeature,
1306
+ rowPaginationFeature,
1307
+ rowSelectionFeature,
1308
+ rowSortingFeature,
1309
+ filteredRowModel: createFilteredRowModel(),
1310
+ paginatedRowModel: createPaginatedRowModel(),
1311
+ sortedRowModel: createSortedRowModel(),
1312
+ filterFns: { includesString: filterFn_includesString },
1313
+ sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text }
1314
+ })
1315
+
1316
+ const columnHelper = createColumnHelper<typeof features, Payment>()
1317
+
1318
+ type Payment = {
1319
+ id: string
1320
+ amount: number
1321
+ status: 'pending' | 'processing' | 'success' | 'failed'
1322
+ email: string
1323
+ }
1324
+
1325
+ const data: Payment[] = [
1326
+ {
1327
+ id: 'm5gr84i9',
1328
+ amount: 316,
1329
+ status: 'success',
1330
+ email: 'ken99@example.com'
1331
+ },
1332
+ {
1333
+ id: '3u1reuv4',
1334
+ amount: 242,
1335
+ status: 'success',
1336
+ email: 'Abe45@example.com'
1337
+ },
1338
+ {
1339
+ id: 'derv1ws0',
1340
+ amount: 837,
1341
+ status: 'processing',
1342
+ email: 'Monserrat44@example.com'
1343
+ },
1344
+ {
1345
+ id: '5kma53ae',
1346
+ amount: 874,
1347
+ status: 'success',
1348
+ email: 'Silas22@example.com'
1349
+ },
1350
+ {
1351
+ id: 'bhqecj4p',
1352
+ amount: 721,
1353
+ status: 'failed',
1354
+ email: 'carmella@example.com'
1355
+ }
1356
+ ]
1357
+
1358
+ export function DataTableRtl() {
1359
+ const { t, dir, language } = useTranslation(translations, 'ar')
1360
+ const [sorting, setSorting] = React.useState<SortingState>([])
1361
+ const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
1362
+ const [columnVisibility, setColumnVisibility] = React.useState<ColumnVisibilityState>({})
1363
+ const [rowSelection, setRowSelection] = React.useState({})
1364
+
1365
+ const columns = React.useMemo(
1366
+ () =>
1367
+ columnHelper.columns([
1368
+ columnHelper.display({
1369
+ id: 'select',
1370
+ header: ({ table }) => (
1371
+ <Checkbox
1372
+ checked={table.getIsAllPageRowsSelected()}
1373
+ indeterminate={table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()}
1374
+ onCheckedChange={value => table.toggleAllPageRowsSelected(!!value)}
1375
+ aria-label={t.selectAll}
1376
+ />
1377
+ ),
1378
+ cell: ({ row }) => (
1379
+ <Checkbox
1380
+ checked={row.getIsSelected()}
1381
+ onCheckedChange={value => row.toggleSelected(!!value)}
1382
+ aria-label={t.selectRow}
1383
+ />
1384
+ ),
1385
+ enableSorting: false,
1386
+ enableHiding: false
1387
+ }),
1388
+ columnHelper.accessor('status', {
1389
+ header: t.status,
1390
+ cell: ({ row }) => {
1391
+ const status = row.getValue('status') as string
1392
+ const statusMap: Record<string, string> = {
1393
+ success: t.success,
1394
+ processing: t.processing,
1395
+ failed: t.failed,
1396
+ pending: t.pending
1397
+ }
1398
+ return <div className="capitalize">{statusMap[status]}</div>
1399
+ }
1400
+ }),
1401
+ columnHelper.accessor('email', {
1402
+ header: ({ column }) => {
1403
+ return (
1404
+ <Button
1405
+ variant="ghost"
1406
+ onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
1407
+ >
1408
+ {t.email}
1409
+ <IconArrowsUpDown stroke={1.5} />
1410
+ </Button>
1411
+ )
1412
+ },
1413
+ cell: ({ row }) => <div className="lowercase">{row.getValue('email')}</div>
1414
+ }),
1415
+ columnHelper.accessor('amount', {
1416
+ header: () => <div className="text-start">{t.amount}</div>,
1417
+ cell: ({ row }) => {
1418
+ const amount = parseFloat(row.getValue('amount'))
1419
+ const formatted = new Intl.NumberFormat(dir === 'rtl' ? 'ar-SA' : 'en-US', {
1420
+ style: 'currency',
1421
+ currency: 'USD'
1422
+ }).format(amount)
1423
+
1424
+ return <div className="text-start font-medium">{formatted}</div>
1425
+ }
1426
+ }),
1427
+ columnHelper.display({
1428
+ id: 'actions',
1429
+ enableHiding: false,
1430
+ cell: ({ row }) => {
1431
+ const payment = row.original
1432
+
1433
+ return (
1434
+ <DropdownMenu>
1435
+ <DropdownMenuTrigger render={<Button variant="ghost" size="icon-xs" />}>
1436
+ <span className="sr-only">{t.openMenu}</span>
1437
+ <IconDots stroke={1.75} />
1438
+ </DropdownMenuTrigger>
1439
+ <DropdownMenuContent
1440
+ align={dir === 'rtl' ? 'start' : 'end'}
1441
+ data-lang={dir === 'rtl' ? language : undefined}
1442
+ className="w-40"
1443
+ >
1444
+ <DropdownMenuGroup>
1445
+ <DropdownMenuLabel>{t.actions}</DropdownMenuLabel>
1446
+ <DropdownMenuItem onClick={() => navigator.clipboard.writeText(payment.id)}>
1447
+ {t.copyPaymentId}
1448
+ </DropdownMenuItem>
1449
+ </DropdownMenuGroup>
1450
+ <DropdownMenuSeparator />
1451
+ <DropdownMenuGroup>
1452
+ <DropdownMenuItem>{t.viewCustomer}</DropdownMenuItem>
1453
+ <DropdownMenuItem>{t.viewPaymentDetails}</DropdownMenuItem>
1454
+ </DropdownMenuGroup>
1455
+ </DropdownMenuContent>
1456
+ </DropdownMenu>
1457
+ )
1458
+ }
1459
+ })
1460
+ ]),
1461
+ [t, dir, language]
1462
+ )
1463
+
1464
+ const table = useTable({
1465
+ features,
1466
+ data,
1467
+ columns,
1468
+ onSortingChange: setSorting,
1469
+ onColumnFiltersChange: setColumnFilters,
1470
+ onColumnVisibilityChange: setColumnVisibility,
1471
+ onRowSelectionChange: setRowSelection,
1472
+ state: {
1473
+ sorting,
1474
+ columnFilters,
1475
+ columnVisibility,
1476
+ rowSelection
1477
+ }
1478
+ })
1479
+
1480
+ return (
1481
+ <div className="w-full">
1482
+ <div className="flex items-center gap-2 py-4">
1483
+ <Input
1484
+ placeholder={t.filterEmails}
1485
+ value={(table.getColumn('email')?.getFilterValue() as string) ?? ''}
1486
+ onChange={event => table.getColumn('email')?.setFilterValue(event.target.value)}
1487
+ className="max-w-sm"
1488
+ />
1489
+ <DropdownMenu>
1490
+ <DropdownMenuTrigger render={<Button variant="outline" className="ms-auto" />}>
1491
+ {t.columns} <IconChevronDown stroke={1.5} />
1492
+ </DropdownMenuTrigger>
1493
+ <DropdownMenuContent
1494
+ align={dir === 'rtl' ? 'start' : 'end'}
1495
+ data-lang={dir === 'rtl' ? language : undefined}
1496
+ >
1497
+ <DropdownMenuGroup>
1498
+ {table
1499
+ .getAllColumns()
1500
+ .filter(column => column.getCanHide())
1501
+ .map(column => {
1502
+ return (
1503
+ <DropdownMenuCheckboxItem
1504
+ key={column.id}
1505
+ className="capitalize"
1506
+ checked={column.getIsVisible()}
1507
+ onCheckedChange={value => column.toggleVisibility(!!value)}
1508
+ >
1509
+ {column.id}
1510
+ </DropdownMenuCheckboxItem>
1511
+ )
1512
+ })}
1513
+ </DropdownMenuGroup>
1514
+ </DropdownMenuContent>
1515
+ </DropdownMenu>
1516
+ </div>
1517
+ <div className="overflow-hidden rounded-md border">
1518
+ <Table>
1519
+ <TableHeader>
1520
+ {table.getHeaderGroups().map(headerGroup => (
1521
+ <TableRow key={headerGroup.id}>
1522
+ {headerGroup.headers.map(header => {
1523
+ return (
1524
+ <TableHead key={header.id}>
1525
+ {header.isPlaceholder ? null : <table.FlexRender header={header} />}
1526
+ </TableHead>
1527
+ )
1528
+ })}
1529
+ </TableRow>
1530
+ ))}
1531
+ </TableHeader>
1532
+ <TableBody>
1533
+ {table.getRowModel().rows?.length ? (
1534
+ table.getRowModel().rows.map(row => (
1535
+ <TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
1536
+ {row.getVisibleCells().map(cell => (
1537
+ <TableCell key={cell.id}>
1538
+ <table.FlexRender cell={cell} />
1539
+ </TableCell>
1540
+ ))}
1541
+ </TableRow>
1542
+ ))
1543
+ ) : (
1544
+ <TableRow>
1545
+ <TableCell colSpan={columns.length} className="h-24 text-center">
1546
+ {t.noResults}
1547
+ </TableCell>
1548
+ </TableRow>
1549
+ )}
1550
+ </TableBody>
1551
+ </Table>
1552
+ </div>
1553
+ <div className="flex items-center justify-end gap-2 py-4">
1554
+ <div className="flex-1 text-sm text-muted-foreground">
1555
+ {table.getFilteredSelectedRowModel().rows.length} {t.rowsSelected}{' '}
1556
+ {table.getFilteredRowModel().rows.length} {t.rowsSelectedSuffix}
1557
+ </div>
1558
+ <div className="flex gap-2">
1559
+ <Button
1560
+ variant="outline"
1561
+ size="sm"
1562
+ onClick={() => table.previousPage()}
1563
+ disabled={!table.getCanPreviousPage()}
1564
+ >
1565
+ {t.previous}
1566
+ </Button>
1567
+ <Button
1568
+ variant="outline"
1569
+ size="sm"
1570
+ onClick={() => table.nextPage()}
1571
+ disabled={!table.getCanNextPage()}
1572
+ >
1573
+ {t.next}
1574
+ </Button>
1575
+ </div>
1576
+ </div>
1577
+ </div>
1578
+ )
1579
+ }
1580
+ ```