Skip to content

Commit cf4d3c6

Browse files
committed
feat(angular): removed tableHelper hook in favor of createTableHook
1 parent b058408 commit cf4d3c6

File tree

11 files changed

+91
-315
lines changed

11 files changed

+91
-315
lines changed

examples/angular/basic/src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, signal } from '@angular/core'
22
import { FlexRender, injectTable, tableFeatures } from '@tanstack/angular-table'
33
import type { ColumnDef } from '@tanstack/angular-table'
44

5-
// This example uses the classic standalone `injectTable` hook to create a table without the new `createTableHelper` util.
5+
// This example uses the classic standalone `injectTable` hook to create a table without the new `createTableHook` util.
66

77
// 1. Define what the shape of your data will be for each row
88
type Person = {
@@ -47,7 +47,7 @@ const defaultData: Array<Person> = [
4747
const _features = tableFeatures({}) // util method to create sharable TFeatures object/type
4848

4949
// 4. Define the columns for your table. This uses the new `ColumnDef` type to define columns.
50-
// Alternatively, check out the createTableHelper/createColumnHelper util for an even more type-safe way to define columns.
50+
// Alternatively, check out the createAppTable/createColumnHelper util for an even more type-safe way to define columns.
5151
const defaultColumns: Array<ColumnDef<typeof _features, Person>> = [
5252
{
5353
accessorKey: 'firstName',

examples/angular/expanding/src/app/app.component.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
FlexRenderDirective,
99
createExpandedRowModel,
1010
createPaginatedRowModel,
11-
createTableHelper,
1211
flexRenderComponent,
12+
injectTable,
1313
rowExpandingFeature,
1414
rowPaginationFeature,
1515
rowSelectionFeature,
@@ -77,15 +77,12 @@ export class AppComponent {
7777
readonly data = signal<Array<Person>>(makeData(100, 5, 3))
7878
readonly expanded = signal<ExpandedState>({})
7979

80-
readonly tableHelper = createTableHelper({
80+
readonly table = injectTable(() => ({
8181
_features,
8282
_rowModels: {
8383
paginatedRowModel: createPaginatedRowModel(),
8484
expandedRowModel: createExpandedRowModel(),
8585
},
86-
})
87-
88-
readonly table = this.tableHelper.injectTable(() => ({
8986
data: this.data(),
9087
columns: defaultColumns,
9188
state: {

examples/angular/grouping/src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
signal,
77
} from '@angular/core'
88
import { FlexRenderDirective, isFunction } from '@tanstack/angular-table'
9-
import { columns, tableHelper } from './columns'
9+
import { columns, injectTable } from './columns'
1010
import { makeData } from './makeData'
1111
import type { GroupingState, Updater } from '@tanstack/angular-table'
1212

@@ -26,7 +26,7 @@ export class AppComponent {
2626
JSON.stringify(this.grouping(), null, 2),
2727
)
2828

29-
readonly table = tableHelper.injectTable(() => ({
29+
readonly table = injectTable(() => ({
3030
data: this.data(),
3131
columns: columns,
3232
initialState: {

examples/angular/grouping/src/app/columns.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,29 @@ import {
66
createFilteredRowModel,
77
createGroupedRowModel,
88
createPaginatedRowModel,
9-
createTableHelper,
9+
createTableHook,
1010
filterFns,
1111
rowExpandingFeature,
1212
rowPaginationFeature,
1313
} from '@tanstack/angular-table'
1414
import type { Person } from './makeData'
1515

16-
export const tableHelper = createTableHelper({
17-
_features: {
18-
columnGroupingFeature,
19-
rowPaginationFeature,
20-
columnFilteringFeature,
21-
rowExpandingFeature,
22-
},
23-
_rowModels: {
24-
groupedRowModel: createGroupedRowModel(aggregationFns),
25-
expandedRowModel: createExpandedRowModel(),
26-
paginatedRowModel: createPaginatedRowModel(),
27-
filteredRowModel: createFilteredRowModel(filterFns),
28-
},
29-
TData: {} as Person,
30-
})
31-
export default tableHelper
32-
33-
const { createColumnHelper } = tableHelper
34-
const columnHelper = createColumnHelper<Person>()
16+
export const { createAppColumnHelper, injectAppTable: injectTable } =
17+
createTableHook({
18+
_features: {
19+
columnGroupingFeature,
20+
rowPaginationFeature,
21+
columnFilteringFeature,
22+
rowExpandingFeature,
23+
},
24+
_rowModels: {
25+
groupedRowModel: createGroupedRowModel(aggregationFns),
26+
expandedRowModel: createExpandedRowModel(),
27+
paginatedRowModel: createPaginatedRowModel(),
28+
filteredRowModel: createFilteredRowModel(filterFns),
29+
},
30+
})
31+
const columnHelper = createAppColumnHelper<Person>()
3532

3633
export const columns = columnHelper.columns([
3734
columnHelper.group({

examples/angular/row-dnd/src/app/app.component.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
FlexRenderDirective,
99
columnSizingFeature,
1010
columnVisibilityFeature,
11-
createPaginatedRowModel,
12-
createTableHelper,
1311
flexRenderComponent,
12+
injectTable,
1413
rowPaginationFeature,
14+
tableFeatures,
1515
} from '@tanstack/angular-table'
1616
import { CdkDrag, CdkDropList, moveItemInArray } from '@angular/cdk/drag-drop'
1717
import { JsonPipe } from '@angular/common'
@@ -21,16 +21,13 @@ import type { Person } from './makeData'
2121
import type { CdkDragDrop } from '@angular/cdk/drag-drop'
2222
import type { ColumnDef } from '@tanstack/angular-table'
2323

24-
const defaultColumns: Array<
25-
ColumnDef<
26-
{
27-
rowPaginationFeature: typeof rowPaginationFeature
28-
columnSizingFeature: typeof columnSizingFeature
29-
columnVisibilityFeature: typeof columnVisibilityFeature
30-
},
31-
Person
32-
>
33-
> = [
24+
const _tableFeatures = tableFeatures({
25+
rowPaginationFeature,
26+
columnSizingFeature,
27+
columnVisibilityFeature,
28+
})
29+
30+
const defaultColumns: Array<ColumnDef<typeof _tableFeatures, Person>> = [
3431
{
3532
id: 'drag-handle',
3633
header: 'Move',
@@ -75,19 +72,9 @@ const defaultColumns: Array<
7572
export class AppComponent {
7673
readonly data = signal<Array<Person>>(makeData(20))
7774

78-
readonly tableHelper = createTableHelper({
79-
_features: {
80-
rowPaginationFeature,
81-
columnSizingFeature,
82-
columnVisibilityFeature,
83-
},
84-
_rowModels: {
85-
paginatedRowModel: createPaginatedRowModel(),
86-
},
87-
})
88-
89-
readonly table = this.tableHelper.injectTable(() => {
75+
readonly table = injectTable(() => {
9076
return {
77+
_features: _tableFeatures,
9178
data: this.data(),
9279
columns: defaultColumns,
9380
getRowId: (row) => row.userId,

examples/angular/row-selection/src/app/app.component.ts

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
columnFilteringFeature,
1111
createFilteredRowModel,
1212
createPaginatedRowModel,
13-
createTableHelper,
13+
createTableHook,
1414
filterFns,
1515
flexRenderComponent,
1616
rowPaginationFeature,
@@ -25,9 +25,9 @@ import {
2525
} from './selection-column.component'
2626
import type { TemplateRef } from '@angular/core'
2727
import type { Person } from './makeData'
28-
import type { ColumnDef, RowSelectionState } from '@tanstack/angular-table'
28+
import type { RowSelectionState } from '@tanstack/angular-table'
2929

30-
const tableHelper = createTableHelper({
30+
const { injectAppTable: injectTable, createAppColumnHelper } = createTableHook({
3131
_features: {
3232
columnFilteringFeature,
3333
rowPaginationFeature,
@@ -40,6 +40,8 @@ const tableHelper = createTableHelper({
4040
debugTable: true,
4141
})
4242

43+
const columnHelper = createAppColumnHelper<Person>()
44+
4345
@Component({
4446
selector: 'app-root',
4547
standalone: true,
@@ -55,65 +57,61 @@ export class AppComponent {
5557
readonly ageHeaderCell =
5658
viewChild.required<TemplateRef<unknown>>('ageHeaderCell')
5759

58-
readonly columns: Array<ColumnDef<typeof tableHelper.features, Person>> = [
59-
{
60+
readonly columns = columnHelper.columns([
61+
columnHelper.display({
6062
id: 'select',
6163
header: () => flexRenderComponent(TableHeadSelectionComponent),
6264
cell: () => flexRenderComponent(TableRowSelectionComponent),
63-
},
64-
{
65+
}),
66+
columnHelper.group({
6567
header: 'Name',
6668
footer: (props) => props.column.id,
67-
columns: [
68-
{
69-
accessorKey: 'firstName',
69+
columns: columnHelper.columns([
70+
columnHelper.accessor('firstName', {
7071
cell: (info) => info.getValue(),
7172
footer: (props) => props.column.id,
72-
header: (props) => `First name`,
73-
},
74-
{
75-
accessorFn: (row) => row.lastName,
76-
id: 'lastName',
73+
header: () => 'First name',
74+
}),
75+
columnHelper.accessor('lastName', {
7776
cell: (info) => info.getValue(),
7877
header: () => 'Last Name',
7978
footer: (props) => props.column.id,
80-
},
81-
],
82-
},
83-
{
79+
}),
80+
]),
81+
}),
82+
columnHelper.group({
8483
header: 'Info',
8584
footer: (props) => props.column.id,
86-
columns: [
87-
{
88-
accessorKey: 'age',
85+
columns: columnHelper.columns([
86+
columnHelper.accessor('age', {
8987
header: () => this.ageHeaderCell(),
9088
footer: (props) => props.column.id,
91-
},
92-
{
89+
}),
90+
columnHelper.group({
9391
header: 'More Info',
94-
columns: [
95-
{
96-
accessorKey: 'visits',
92+
columns: columnHelper.columns([
93+
columnHelper.accessor((row) => row.visits, {
94+
id: 'visits',
9795
header: () => 'Visits',
9896
footer: (props) => props.column.id,
99-
},
100-
{
101-
accessorKey: 'status',
102-
header: 'Status',
97+
}),
98+
columnHelper.accessor((row) => row.status, {
99+
id: 'status',
100+
header: () => 'Status',
103101
footer: (props) => props.column.id,
104-
},
105-
{
106-
accessorKey: 'progress',
102+
}),
103+
columnHelper.accessor((row) => row.progress, {
104+
id: 'progress',
107105
header: 'Profile Progress',
108106
footer: (props) => props.column.id,
109-
},
110-
],
111-
},
112-
],
113-
},
114-
]
107+
}),
108+
]),
109+
}),
110+
]),
111+
}),
112+
])
115113

116-
table = tableHelper.injectTable(() => ({
114+
table = injectTable(() => ({
117115
data: this.data(),
118116
columns: this.columns,
119117
state: {

examples/angular/signal-input/src/app/person-table/person-table.component.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,16 @@ import { ChangeDetectionStrategy, Component, input, model } from '@angular/core'
22
import {
33
FlexRenderDirective,
44
columnVisibilityFeature,
5-
createPaginatedRowModel,
6-
createTableHelper,
5+
injectTable,
76
rowPaginationFeature,
7+
tableFeatures,
88
} from '@tanstack/angular-table'
99
import type { ColumnDef, PaginationState } from '@tanstack/angular-table'
1010
import type { Person } from '../makeData'
1111

12-
const tableHelper = createTableHelper({
13-
_features: {
14-
rowPaginationFeature,
15-
columnVisibilityFeature,
16-
},
17-
_rowModels: {
18-
paginatedRowModel: createPaginatedRowModel(),
19-
},
12+
const _features = tableFeatures({
13+
rowPaginationFeature,
14+
columnVisibilityFeature,
2015
})
2116

2217
@Component({
@@ -30,7 +25,7 @@ export class PersonTableComponent {
3025

3126
readonly pagination = model.required<PaginationState>()
3227

33-
readonly columns: Array<ColumnDef<typeof tableHelper.features, Person>> = [
28+
readonly columns: Array<ColumnDef<typeof _features, Person>> = [
3429
{
3530
accessorKey: 'firstName',
3631
header: 'First Name',
@@ -44,8 +39,9 @@ export class PersonTableComponent {
4439
},
4540
]
4641

47-
readonly table = tableHelper.injectTable(() => {
42+
readonly table = injectTable(() => {
4843
return {
44+
_features,
4945
data: this.data(),
5046
columns: this.columns,
5147
state: {

0 commit comments

Comments
 (0)