11<!-- eslint-disable vue/block-tag-newline -->
22<script lang="ts">
3- import type { Ref } from ' vue'
3+ import type { Ref , WatchOptions } from ' vue'
44import type { AppConfig } from ' @nuxt/schema'
55import type { Cell , Header , RowData , TableMeta } from ' @tanstack/table-core'
66import type {
@@ -97,6 +97,13 @@ export interface TableProps<T extends TableData> extends TableOptions<T> {
9797 * @defaultValue 'carousel'
9898 */
9999 loadingAnimation? : Table [' variants' ][' loadingAnimation' ]
100+ /**
101+ * Use the `watchOptions` prop to customize reactivity (for ex: disable deep watching for changes in your data or limiting the max traversal depth). This can improve performance by reducing unnecessary re-renders, but it should be used with caution as it may lead to unexpected behavior if not managed properly.
102+ * @link [API Docs](https://vuejs.org/api/options-state.html#watch)
103+ * @link [Guide](https://vuejs.org/guide/essentials/watchers.html)
104+ * @defaultValue { deep: true }
105+ */
106+ watchOptions? : WatchOptions
100107 /**
101108 * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#table-options)
102109 * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)
@@ -175,7 +182,7 @@ export type TableSlots<T> = {
175182 </script >
176183
177184<script setup lang="ts" generic =" T extends TableData " >
178- import { computed , ref } from ' vue'
185+ import { computed , ref , watch } from ' vue'
179186import { Primitive } from ' reka-ui'
180187import { upperFirst } from ' scule'
181188import { FlexRender , getCoreRowModel , getFilteredRowModel , getSortedRowModel , getExpandedRowModel , useVueTable } from ' @tanstack/vue-table'
@@ -184,13 +191,17 @@ import { useAppConfig } from '#imports'
184191import { useLocale } from ' ../composables/useLocale'
185192import { tv } from ' ../utils/tv'
186193
187- const props = defineProps <TableProps <T >>()
194+ const props = withDefaults (defineProps <TableProps <T >>(), {
195+ watchOptions : () => ({
196+ deep: true
197+ })
198+ })
188199const slots = defineSlots <TableSlots <T >>()
189200
190201const { t } = useLocale ()
191202const appConfig = useAppConfig () as Table [' AppConfig' ]
192203
193- const data = computed (() => props .data ?? [])
204+ const data = ref ( props .data ?? []) as Ref < T []>
194205const columns = computed <TableColumn <T >[]>(() => props .columns ?? Object .keys (data .value [0 ] ?? {}).map ((accessorKey : string ) => ({ accessorKey , header: upperFirst (accessorKey ) })))
195206const meta = computed (() => props .meta ?? {})
196207
@@ -314,6 +325,12 @@ function handleRowSelect(row: TableRow<T>, e: Event) {
314325 props .onSelect (row , e )
315326}
316327
328+ watch (
329+ () => props .data , () => {
330+ data .value = props .data ? [... props .data ] : []
331+ }, props .watchOptions
332+ )
333+
317334defineExpose ({
318335 tableRef ,
319336 tableApi
0 commit comments