From ed22471564dd8fc011671395e99f26c0179a2dcb Mon Sep 17 00:00:00 2001 From: Kevin Van Cott Date: Sat, 4 Jan 2025 13:16:04 -0600 Subject: [PATCH] fix vue adapter and examples for v9 --- examples/vue/basic/src/App.vue | 19 +-- examples/vue/column-ordering/src/App.vue | 43 +++--- examples/vue/column-pinning/src/App.vue | 126 ++++++++-------- examples/vue/filters/src/App.vue | 135 +++++++----------- examples/vue/filters/src/Filter.vue | 6 +- examples/vue/filters/src/tableHelper.ts | 35 +++++ .../vue/pagination-controlled/src/App.vue | 21 ++- .../pagination-controlled/src/useService.ts | 5 +- examples/vue/pagination/src/App.vue | 117 ++++++++------- examples/vue/row-selection/src/App.vue | 35 +++-- examples/vue/sorting/src/App.vue | 78 ++++------ examples/vue/sub-components/src/App.vue | 103 +++++++------ examples/vue/virtualized-rows/src/App.vue | 27 ++-- .../svelte-table/src/createTable.svelte.ts | 2 + packages/vue-table/src/FlexRender.ts | 17 +++ packages/vue-table/src/createTableHelper.ts | 62 ++++++++ packages/vue-table/src/index.ts | 133 +---------------- packages/vue-table/src/useTable.ts | 108 ++++++++++++++ 18 files changed, 579 insertions(+), 493 deletions(-) create mode 100644 examples/vue/filters/src/tableHelper.ts create mode 100644 packages/vue-table/src/FlexRender.ts create mode 100644 packages/vue-table/src/createTableHelper.ts create mode 100644 packages/vue-table/src/useTable.ts diff --git a/examples/vue/basic/src/App.vue b/examples/vue/basic/src/App.vue index 219a516b13..d806ba9ea2 100644 --- a/examples/vue/basic/src/App.vue +++ b/examples/vue/basic/src/App.vue @@ -1,7 +1,6 @@ @@ -132,7 +133,7 @@ const table = useTable({ - + import { - type ColumnOrderState, FlexRender, - createCoreRowModel, - useTable, - type Column, - createColumnHelper, - type ColumnVisibilityState, columnOrderingFeature, + columnVisibilityFeature, + createColumnHelper, tableFeatures, + type Column, + type ColumnOrderState, + type ColumnVisibilityState, + useTable, + Updater, + isFunction, } from '@tanstack/vue-table' import { makeData, type Person } from './makeData' import { ref } from 'vue' import { faker } from '@faker-js/faker' -const _features = tableFeatures({ columnOrderingFeature }) +const _features = tableFeatures({ + columnOrderingFeature, + columnVisibilityFeature, +}) const columnHelper = createColumnHelper() @@ -25,7 +30,7 @@ const columns = ref( columnHelper.group({ header: 'Name', footer: (props) => props.column.id, - columns: [ + columns: columnHelper.columns([ columnHelper.accessor('firstName', { cell: (info) => info.getValue(), footer: (props) => props.column.id, @@ -36,19 +41,19 @@ const columns = ref( header: () => 'Last Name', footer: (props) => props.column.id, }), - ], + ]), }), columnHelper.group({ header: 'Info', footer: (props) => props.column.id, - columns: [ + columns: columnHelper.columns([ columnHelper.accessor('age', { header: () => 'Age', footer: (props) => props.column.id, }), columnHelper.group({ header: 'More Info', - columns: [ + columns: columnHelper.columns([ columnHelper.accessor('visits', { header: () => 'Visits', footer: (props) => props.column.id, @@ -61,9 +66,9 @@ const columns = ref( header: 'Profile Progress', footer: (props) => props.column.id, }), - ], + ]), }), - ], + ]), }), ]), ) @@ -74,6 +79,7 @@ const columnOrder = ref([]) const rerender = () => (data.value = makeData(20)) const table = useTable({ + _features, get data() { return data.value }, @@ -88,14 +94,11 @@ const table = useTable({ return columnOrder.value }, }, - - onColumnOrderChange: (updaterOrValue) => { - columnOrder.value = - updaterOrValue === 'function' - ? updaterOrValue(columnOrder.value) - : updaterOrValue + onColumnOrderChange: (updaterOrValue: Updater) => { + columnOrder.value = isFunction(updaterOrValue) + ? updaterOrValue(columnOrder.value) + : updaterOrValue }, - getCoreRowModel: createCoreRowModel(), debugTable: true, debugHeaders: true, debugColumns: true, diff --git a/examples/vue/column-pinning/src/App.vue b/examples/vue/column-pinning/src/App.vue index 379b6f04f1..ac6f79c25e 100644 --- a/examples/vue/column-pinning/src/App.vue +++ b/examples/vue/column-pinning/src/App.vue @@ -1,17 +1,19 @@ @@ -133,7 +142,7 @@ const table = useTable({ - + () -const columns = [ - columnHelper.group({ - header: 'Name', +const columns = columnHelper.columns([ + columnHelper.accessor('firstName', { + cell: (info) => info.getValue(), footer: (props) => props.column.id, - columns: [ - columnHelper.accessor('firstName', { - cell: (info) => info.getValue(), - footer: (props) => props.column.id, - }), - - columnHelper.accessor((row) => row.lastName, { - id: 'lastName', - cell: (info) => info.getValue(), - header: () => h('span', 'Last Name'), - footer: (props) => props.column.id, - }), - ], }), - - columnHelper.group({ - header: 'Info', + columnHelper.accessor((row) => row.lastName, { + id: 'lastName', + cell: (info) => info.getValue(), + header: () => h('span', 'Last Name'), footer: (props) => props.column.id, - - columns: [ - columnHelper.accessor('age', { - header: () => 'Age', - footer: (props) => props.column.id, - }), - - columnHelper.group({ - header: 'More Info', - columns: [ - columnHelper.accessor('visits', { - header: () => h('span', 'Visits'), - footer: (props) => props.column.id, - }), - - columnHelper.accessor('status', { - header: 'Status', - footer: (props) => props.column.id, - }), - - columnHelper.accessor('progress', { - header: 'Profile Progress', - footer: (props) => props.column.id, - }), - ], - }), - - columnHelper.accessor('createdAt', { - header: 'Created At', - }), - ], }), -] + columnHelper.accessor('age', { + header: () => 'Age', + footer: (props) => props.column.id, + }), + columnHelper.accessor('visits', { + header: () => h('span', 'Visits'), + footer: (props) => props.column.id, + }), + columnHelper.accessor('status', { + header: 'Status', + footer: (props) => props.column.id, + }), + columnHelper.accessor('progress', { + header: 'Profile Progress', + footer: (props) => props.column.id, + }), + columnHelper.accessor('createdAt', { + header: 'Created At', + }), +]) const data = ref(makeData(10000)) diff --git a/examples/vue/sub-components/src/App.vue b/examples/vue/sub-components/src/App.vue index 0cd88e62cf..b2a97988ff 100644 --- a/examples/vue/sub-components/src/App.vue +++ b/examples/vue/sub-components/src/App.vue @@ -1,14 +1,14 @@