Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular-table): adds Angular adapter for tanstack/table (#5326) #5432

Merged
merged 45 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
afa27ad
feat(angular-table): adds Angular adapter for tanstack/table (#5326)
jrgokavalsa Mar 25, 2024
54034ef
docs config cleanup
KevinVandy Mar 25, 2024
a36a507
Merge branch 'main' into feat-angular-table
KevinVandy Mar 26, 2024
f118589
Merge branch 'main' into feat-angular-table
KevinVandy Mar 26, 2024
361577e
feat: signal angular table adapter implementation
riccardoperra Mar 26, 2024
8516ea7
feat: table proxy detect memoized fns
riccardoperra Mar 26, 2024
9b195b3
fix proxy property returning value
riccardoperra Mar 26, 2024
bf32e66
feat: improve naming
riccardoperra Mar 26, 2024
129f921
save new reference of table signal on every update
riccardoperra Mar 27, 2024
3aab637
computed trap proxy for fns with 1 argument
riccardoperra Mar 27, 2024
d0bd1dc
Merge branch 'main' into feat-angular-table
KevinVandy Mar 28, 2024
6b5d921
Merge branch 'main' into feat-angular-table
KevinVandy Apr 1, 2024
5817368
Merge remote-tracking branch 'origin/main' into feat-angular-table
riccardoperra Apr 29, 2024
1aa5353
update pnpm-lock.yaml
riccardoperra Apr 29, 2024
c5b1e71
refactor proxy implementation
riccardoperra Apr 29, 2024
6df7cf6
fix dependencies
riccardoperra Apr 29, 2024
b450b3d
cleanup imports
riccardoperra Apr 29, 2024
071ce7a
refactor basic example
riccardoperra Apr 29, 2024
fd0ca50
fix build
riccardoperra Apr 29, 2024
8d6f123
run prettier
riccardoperra Apr 29, 2024
3015158
add grouping example, fix ci
riccardoperra May 1, 2024
213b7a6
add grouping example, fix ci
riccardoperra May 1, 2024
2ff60af
add row selection example
riccardoperra May 1, 2024
1cdec2a
add column visibility example
riccardoperra May 1, 2024
dd68ab3
update examples add signal input required example
riccardoperra May 2, 2024
a571cba
improve angular table impl, fix flex-render change detection issues
riccardoperra May 2, 2024
f651c6c
fix build
riccardoperra May 2, 2024
38879fd
Merge branch 'main' into feat-angular-table
KevinVandy May 3, 2024
d4c514a
feat(angular-table): improve adapter implementation (#5524)
riccardoperra May 4, 2024
67a0b10
example cleanup
KevinVandy May 5, 2024
ca9491c
update lock file
KevinVandy May 5, 2024
7af1fd6
feat(angular-table): added injector optional parameter for more flexi…
merto20 May 7, 2024
804a0d2
Merge branch 'main' into feat-angular-table
KevinVandy May 9, 2024
f567280
update angular adapter and state docs
KevinVandy May 9, 2024
df4f32b
prettier
KevinVandy May 9, 2024
1518ea8
Merge branch 'main' into feat-angular-table
KevinVandy May 10, 2024
8493be0
update docs config with angular examples
KevinVandy May 10, 2024
412c76c
update angular table state docs (#5545)
riccardoperra May 12, 2024
2c916d2
Angular examples and dependencies improvements (#5546)
arnoud-dv May 12, 2024
059c018
docs(angular-table): Add documentation for FlexRenderDirective (#5543)
riccardoperra May 12, 2024
abf605c
remove double build package.json from angular build
KevinVandy May 12, 2024
9984118
update link name
KevinVandy May 12, 2024
ea7da50
docs pass
KevinVandy May 12, 2024
4dc3d72
update esm exports in package.json
KevinVandy May 12, 2024
529bc29
update flexrender types
KevinVandy May 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ stats.html
*.log
.DS_Store
.cache
.idea
.pnpm-store

package-lock.json
Expand All @@ -49,3 +50,5 @@ yarn.lock
.nx/cache
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

.angular
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
**/docs
**/old-examples
pnpm-lock.yaml

.angular
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Try other [TanStack](https://tanstack.com) libraries:

You may know **TanStack Table** by our adapter names, too!

- [Angular Table](https://tanstack.com/table/v8/docs/adapters/angular-table)
- [Qwik Table](https://tanstack.com/table/v8/docs/adapters/qwik-table)
- [**React Table**](https://tanstack.com/table/v8/docs/adapters/react-table)
- [Solid Table](https://tanstack.com/table/v8/docs/adapters/solid-table)
Expand Down Expand Up @@ -115,6 +116,7 @@ Install one of the following packages based on your framework of choice:

```bash
# Npm
npm install @tanstack/angular-table
npm install @tanstack/qwik-table
npm install @tanstack/react-table
npm install @tanstack/solid-table
Expand Down
2 changes: 1 addition & 1 deletion docs/api/core/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Table APIs
---

## `useReactTable` / `createSolidTable` / `useQwikTable` / `useVueTable` / `createSvelteTable`
## `createAngularTable` / `useReactTable` / `createSolidTable` / `useQwikTable` / `useVueTable` / `createSvelteTable`

```tsx
type useReactTable = <TData extends AnyData>(
Expand Down
59 changes: 59 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
}
],
"frameworks": [
{
"label": "angular",
"children": [
{
"label": "Angular Table Adapter",
"to": "framework/angular/angular-table"
}
]
},
{
"label": "qwik",
"children": [
Expand Down Expand Up @@ -128,6 +137,15 @@
}
],
"frameworks": [
{
"label": "angular",
"children": [
{
"label": "Table State",
"to": "framework/angular/guide/table-state"
}
]
},
{
"label": "qwik",
"children": [
Expand Down Expand Up @@ -364,6 +382,47 @@
"label": "Examples",
"children": [],
"frameworks": [
{
"label": "angular",
"children": [
{
"to": "framework/angular/examples/basic",
"label": "Basic"
},
{
"to": "framework/angular/examples/grouping",
"label": "Column Grouping"
},
{
"to": "framework/angular/examples/column-ordering",
"label": "Column Ordering"
},
{
"to": "framework/angular/examples/column-pinning",
"label": "Column Pinning"
},
{
"to": "column-pinning-sticky",
"label": "Sticky Column Pinning"
},
{
"to": "framework/angular/examples/column-visibility",
"label": "Column Visibility"
},
{
"to": "framework/angular/examples/filters",
"label": "Column Filters"
},
{
"to": "framework/angular/examples/row-selection",
"label": "Row Selection"
},
{
"to": "framework/angular/examples/signal-input",
"label": "Signal Input"
}
]
},
{
"label": "qwik",
"children": [
Expand Down
217 changes: 217 additions & 0 deletions docs/framework/angular/angular-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
---
title: Angular Table
---

The `@tanstack/angular-table` adapter is a wrapper around the core table logic. Most of it's job is related to managing
state the "angular signals" way, providing types and the rendering implementation of cell/header/footer templates.

## Exports

`@tanstack/angular-table` re-exports all of `@tanstack/table-core`'s and the following:

### `createAngularTable`

Accepts an options function or a computed value that returns the table options, and returns a table.

```ts
import {createAngularTable} from '@tanstack/angular-table'

export class AppComponent {
data = signal<Person[]>([])

table = createAngularTable(() => ({
data: this.data(),
columns: defaultColumns,
getCoreRowModel: getCoreRowModel(),
}))
}

// ...render your table in template

```

### `FlexRender`

An Angular structural directive for rendering cell/header/footer templates with dynamic values.

FlexRender supports any type of content supported by Angular:

- A string, or a html string via `innerHTML`
- A [TemplateRef](https://angular.dev/api/core/TemplateRef)
- A [Component](https://angular.dev/api/core/Component) wrapped into `FlexRenderComponent`

Example:

```ts
@Component({
imports: [FlexRenderDirective],
//...
})
```

```angular2html

<tbody>
@for (row of table.getRowModel().rows; track row.id) {
<tr>
@for (cell of row.getVisibleCells(); track cell.id) {
<td>
<ng-container
*flexRender="
cell.column.columnDef.cell;
props: cell.getContext();
let cell
"
>
<!-- if you want to render a simple string -->
{{ cell }}
<!-- if you want to render an html string -->
<div [innerHTML]="cell"></div>
</ng-container>
</td>
}
</tr>
}
</tbody>
```

#### Rendering a TemplateRef

In order to render a TemplateRef into a specific column header/cell/footer, you can pass the TemplateRef into the column
definition.

You can access the TemplateRef data via the `$implicit` property, which is valued based on what is passed in the props
field of flexRender.

In most cases, each TemplateRef will be rendered with the $implicit context valued based on the cell type in this way:

- Header: `HeaderContext<T, ?>`
- Cell: `CellContext<T, ?>`,
- Footer: `HeaderContext<T, ?>`

```angular17html

<ng-container
*flexRender="
cell.column.columnDef.cell;
props: cell.getContext();
let cell
"
>
<!-- if you want to render a simple string -->
{{ cell }}
<!-- if you want to render an html string -->
<div [innerHTML]="cell"></div>
</ng-container>

<ng-template #myCell let-context>
<!-- render something with context -->
</ng-template>
```

Full example:

```ts
import type {
CellContext,
ColumnDef,
HeaderContext,
} from '@tanstack/angular-table'
import {Component, TemplateRef, viewChild} from '@angular/core'

@Component({
template: `
<tbody>
@for (row of table.getRowModel().rows; track row.id) {
<tr>
@for (cell of row.getVisibleCells(); track cell.id) {
<td>
<ng-container
*flexRender="
cell.column.columnDef.cell;
props: cell.getContext(); // Data given to the TemplateRef
let cell
"
>
<!-- if you want to render a simple string -->
{{ cell }}
<!-- if you want to render an html string -->
<div [innerHTML]="cell"></div>
</ng-container>
</td>
}
</tr>
}
</tbody>

<ng-template #customHeader let-context>
{{ context.getValue() }}
</ng-template>
<ng-template #customCell let-context>
{{ context.getValue() }}
</ng-template>
`,
})
class AppComponent {
customHeader =
viewChild.required<TemplateRef<{ $implicit: HeaderContext<any, any> }>>(
'customHeader'
)
customCell =
viewChild.required<TemplateRef<{ $implicit: CellContext<any, any> }>>(
'customCell'
)

columns: ColumnDef<unknown>[] = [
{
id: 'customCell',
header: () => this.customHeader(),
cell: () => this.customCell(),
},
]
}
```

#### Rendering a Component

To render a Component into a specific column header/cell/footer, you can pass a `FlexRenderComponent instantiated with
your `ComponentType, with the ability to include optional parameters such as inputs and an injector.

```ts
import {FlexRenderComponent} from "@tanstack/angular-table";

class AppComponent {
columns: ColumnDef<unknown>[] = [
{
id: 'customCell',
header: () => new FlexRenderComponent(
CustomCellComponent,
{}, // optional inputs
injector // optional injector
),
cell: () => this.customCell(),
},
]
}
```

Underneath, this utilizes
the [ViewContainerRef#createComponent](https://angular.dev/api/core/ViewContainerRef#createComponent) api.
Therefore, you should declare your custom inputs using the @Input decorator or input/model signals.

You can still access the table cell context through the `injectFlexRenderContext` function, which returns the context
value based on the props you pass to the `FlexRenderDirective`.

```ts
@Component({
// ...
})
class CustomCellComponent {
// context of a cell component
readonly context = injectFlexRenderContext<CellContext<TData, TValue>>();
// context of a header/footer component
readonly context = injectFlexRenderContext<HeaderContext<TData, TValue>>();
}
```


Loading
Loading