Skip to content

Commit

Permalink
fix grouping example
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Dec 21, 2024
1 parent 14488f5 commit 25dc0d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
28 changes: 16 additions & 12 deletions examples/angular/grouping/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CommonModule } from '@angular/common'
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -13,6 +14,7 @@ import {
createFilteredRowModel,
createGroupedRowModel,
createPaginatedRowModel,
createTableHelper,
filterFns,
injectTable,
isFunction,
Expand All @@ -21,7 +23,7 @@ import {
tableFeatures,
} from '@tanstack/angular-table'
import { columns } from './columns'
import { makeData } from './makeData'
import { makeData, Person } from './makeData'
import type { GroupingState, Updater } from '@tanstack/angular-table'

export const _features = tableFeatures({
Expand All @@ -31,10 +33,20 @@ export const _features = tableFeatures({
rowExpandingFeature,
})

const tableHelper = createTableHelper<typeof _features, Person>({
_features,
_rowModels: {
groupedRowModel: createGroupedRowModel(aggregationFns),
expandedRowModel: createExpandedRowModel(),
paginatedRowModel: createPaginatedRowModel(),
filteredRowModel: createFilteredRowModel(filterFns),
},
})

@Component({
selector: 'app-root',
standalone: true,
imports: [FlexRenderDirective],
imports: [FlexRenderDirective, CommonModule],
templateUrl: './app.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand All @@ -47,18 +59,10 @@ export class AppComponent {
JSON.stringify(this.grouping(), null, 2),
)

readonly table = injectTable(() => ({
_features,
_rowModels: {
groupedRowModel: createGroupedRowModel(aggregationFns),
expandedRowModel: createExpandedRowModel(),
paginatedRowModel: createPaginatedRowModel(),
filteredRowModel: createFilteredRowModel(filterFns),
},
readonly table = tableHelper.injectTable(() => ({
enableExperimentalReactivity: true,
data: this.data(),
// @ts-expect-error Fix this type
columns,
columns: columns,
initialState: {
pagination: { pageSize: 20, pageIndex: 0 },
},
Expand Down
11 changes: 1 addition & 10 deletions examples/angular/grouping/src/app/columns.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import type { Person } from './makeData'
import type { _features } from './app.component'
import type { ColumnDef } from '@tanstack/angular-table'

export type Person = {
firstName: string
lastName: string
age: number
visits: number
progress: number
status: 'relationship' | 'complicated' | 'single'
subRows?: Array<Person>
}

export const columns: Array<ColumnDef<typeof _features, Person>> = [
{
header: 'Name',
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/grouping/src/app/makeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const newPerson = (): Person => {
}
}

export function makeData(...lens: Array<number>) {
export function makeData(...lens: Array<number>): Array<Person> {
const makeDataLevel = (depth = 0): Array<Person> => {
const len = lens[depth]
return range(len).map((d): Person => {
Expand Down

0 comments on commit 25dc0d1

Please sign in to comment.