-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathapp.ts
More file actions
107 lines (99 loc) · 2.9 KB
/
app.ts
File metadata and controls
107 lines (99 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { ChangeDetectionStrategy, Component, signal } from '@angular/core'
import { FlexRender, injectTable, tableFeatures } from '@tanstack/angular-table'
import type { ColumnDef } from '@tanstack/angular-table'
// This example uses the classic standalone `injectTable` hook to create a table without the new `createTableHook` util.
// 1. Define what the shape of your data will be for each row
type Person = {
firstName: string
lastName: string
age: number
visits: number
status: string
progress: number
}
// 2. Create some dummy data
const defaultData: Array<Person> = [
{
firstName: 'tanner',
lastName: 'linsley',
age: 24,
visits: 100,
status: 'In Relationship',
progress: 50,
},
{
firstName: 'tandy',
lastName: 'miller',
age: 40,
visits: 40,
status: 'Single',
progress: 80,
},
{
firstName: 'joe',
lastName: 'dirte',
age: 45,
visits: 20,
status: 'Complicated',
progress: 10,
},
]
// 3. New in V9! Tell the table which features and row models we want to use.
// In this case, this will be a basic table with no additional features
const _features = tableFeatures({}) // util method to create sharable TFeatures object/type
// 4. Define the columns for your table. This uses the new `ColumnDef` type to define columns.
// Alternatively, check out the createAppTable/createColumnHelper util for an even more type-safe way to define columns.
const defaultColumns: Array<ColumnDef<typeof _features, Person>> = [
{
accessorKey: 'firstName',
cell: (info) => info.getValue(),
footer: (info) => info.column.id,
},
{
accessorFn: (row) => row.lastName,
id: 'lastName',
cell: (info) => `<i>${info.getValue<string>()}</i>`,
header: () => `<span>Last Name</span>`,
footer: (info) => info.column.id,
},
{
accessorKey: 'age',
header: () => 'Age',
footer: (info) => info.column.id,
},
{
accessorKey: 'visits',
header: () => `<span>Visits</span>`,
footer: (info) => info.column.id,
},
{
accessorKey: 'status',
header: 'Status',
footer: (info) => info.column.id,
},
{
accessorKey: 'progress',
header: 'Profile Progress',
footer: (info) => info.column.id,
},
]
@Component({
selector: 'app-root',
imports: [FlexRender],
templateUrl: './app.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class App {
readonly data = signal<Array<Person>>(defaultData)
// 5. Create the table instance with required _features, columns, and data
table = injectTable(() => ({
_features, // new required option in V9. Tell the table which features you are importing and using (better tree-shaking)
_rowModels: {}, // `Core` row model is now included by default, but you can still override it here
data: this.data(),
columns: defaultColumns,
// ...other options here
}))
rerender() {
this.data.set([...defaultData.sort(() => -1)])
}
}