From 481bebf413f0e6bc14c52cf3a6dfb9e89f809d15 Mon Sep 17 00:00:00 2001
From: Roman Hrynevych <82209198+romanhrynevych@users.noreply.github.com>
Date: Sat, 31 Aug 2024 10:31:36 +0300
Subject: [PATCH] docs(data-table): add DataTableReactive example (#744)
* docs(table): add `DataTableReactive` example and tanstack docs
* chore: build:registry
* docs: refrase
* docs(data-table): update `defineModel`
* fix(data-table): change `reactive` data to `shallowRef`
* docs(data-table): add info about `ref` and `shallowRef`
---
apps/www/__registry__/index.ts | 14 +
.../src/content/docs/components/data-table.md | 14 +
.../default/example/DataTableReactiveDemo.vue | 273 ++++++++++++++++++
.../example/DataTableReactiveDemo.vue | 273 ++++++++++++++++++
4 files changed, 574 insertions(+)
create mode 100644 apps/www/src/lib/registry/default/example/DataTableReactiveDemo.vue
create mode 100644 apps/www/src/lib/registry/new-york/example/DataTableReactiveDemo.vue
diff --git a/apps/www/__registry__/index.ts b/apps/www/__registry__/index.ts
index fa662581..4f3683db 100644
--- a/apps/www/__registry__/index.ts
+++ b/apps/www/__registry__/index.ts
@@ -521,6 +521,13 @@ export const Index = {
component: () => import("../src/lib/registry/default/example/DataTableDemoColumn.vue").then((m) => m.default),
files: ["../src/lib/registry/default/example/DataTableDemoColumn.vue"],
},
+ "DataTableReactiveDemo": {
+ name: "DataTableReactiveDemo",
+ type: "components:example",
+ registryDependencies: ["button","checkbox","dropdown-menu","input","table","utils"],
+ component: () => import("../src/lib/registry/default/example/DataTableReactiveDemo.vue").then((m) => m.default),
+ files: ["../src/lib/registry/default/example/DataTableReactiveDemo.vue"],
+ },
"DatePickerDemo": {
name: "DatePickerDemo",
type: "components:example",
@@ -2013,6 +2020,13 @@ export const Index = {
component: () => import("../src/lib/registry/new-york/example/DataTableDemoColumn.vue").then((m) => m.default),
files: ["../src/lib/registry/new-york/example/DataTableDemoColumn.vue"],
},
+ "DataTableReactiveDemo": {
+ name: "DataTableReactiveDemo",
+ type: "components:example",
+ registryDependencies: ["button","checkbox","dropdown-menu","input","table","utils"],
+ component: () => import("../src/lib/registry/new-york/example/DataTableReactiveDemo.vue").then((m) => m.default),
+ files: ["../src/lib/registry/new-york/example/DataTableReactiveDemo.vue"],
+ },
"DatePickerDemo": {
name: "DatePickerDemo",
type: "components:example",
diff --git a/apps/www/src/content/docs/components/data-table.md b/apps/www/src/content/docs/components/data-table.md
index b43074b4..eb355716 100644
--- a/apps/www/src/content/docs/components/data-table.md
+++ b/apps/www/src/content/docs/components/data-table.md
@@ -55,6 +55,20 @@ npm install @tanstack/vue-table
+### Reactive Table
+
+A reactive table was added in `v8.20.0` of the TanStack Table. You can see the [docs](https://tanstack.com/table/latest/docs/framework/vue/guide/table-state#using-reactive-data) for more information. We added an example where we are randomizing `status` column. One main point is that you need to mutate **full** data, as it is a `shallowRef` object.
+
+> __*⚠️ `shallowRef` is used under the hood for performance reasons, meaning that the data is not deeply reactive, only the `.value` is. To update the data you have to mutate the data directly.*__
+
+Relative PR: [Tanstack/table #5687](https://github.com/TanStack/table/pull/5687#issuecomment-2281067245)
+
+If you want to mutate `props.data`, you should use [`defineModel`](https://vuejs.org/api/sfc-script-setup.html#definemodel).
+
+There is no difference between using `ref` or `shallowRef` for your data object; it will be automatically mutated by the TanStack Table to `shallowRef`.
+
+
+
## Prerequisites
We are going to build a table to show recent payments. Here's what our data looks like:
diff --git a/apps/www/src/lib/registry/default/example/DataTableReactiveDemo.vue b/apps/www/src/lib/registry/default/example/DataTableReactiveDemo.vue
new file mode 100644
index 00000000..b89847dc
--- /dev/null
+++ b/apps/www/src/lib/registry/default/example/DataTableReactiveDemo.vue
@@ -0,0 +1,273 @@
+
+
+
+