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): angular adapter implementation with signals #5442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions examples/angular/basic/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"newProjectRoot": "projects",
"projects": {
"basic": {
"cli": {
"cache": {
"enabled": false
}
},
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
Expand Down
100 changes: 48 additions & 52 deletions examples/angular/basic/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
@if (table) {
<table aria-describedby="tanstack basic implementation in angular">
<thead>
@for (headerGroup of table.getHeaderGroups(); track headerGroup.id) {
<tr>
@for (header of headerGroup.headers; track header.id) {
@if (!header.isPlaceholder) {
<th>
<ng-container
*flexRender="
<table aria-describedby="tanstack basic implementation in angular">
<thead>
@for (headerGroup of table.getHeaderGroups(); track headerGroup.id) {
<tr>
@for (header of headerGroup.headers; track header.id) {
@if (!header.isPlaceholder) {
<th>
<ng-container
*flexRender="
header.column.columnDef.header;
props: header.getContext();
let header
"
>
{{ header }}
</ng-container>
</th>
}
>
{{ header }}
</ng-container>
</th>
}
</tr>
}
</thead>
<tbody>
@for (row of table.getRowModel().rows; track row.id) {
<tr>
@for (cell of row.getVisibleCells(); track cell.id) {
<td>
<ng-container
*flexRender="
}
</tr>
}
</thead>
<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
"
>
{{ cell }}
</ng-container>
</td>
}
</tr>
}
</tbody>
<tfoot>
@for (footerGroup of table.getFooterGroups(); track footerGroup.id) {
<tr>
@for (footer of footerGroup.headers; track footer.id) {
<th>
<ng-container
*flexRender="
>
{{ cell }}
</ng-container>
</td>
}
</tr>
}
</tbody>
<tfoot>
@for (footerGroup of table.getFooterGroups(); track footerGroup.id) {
<tr>
@for (footer of footerGroup.headers; track footer.id) {
<th>
<ng-container
*flexRender="
footer.column.columnDef.footer;
props: footer.getContext();
let footer
"
>
{{ footer }}
</ng-container>
</th>
}
</tr>
}
</tfoot>
</table>
} @else {
<p>loading...</p>
}
>
{{ footer }}
</ng-container>
</th>
}
</tr>
}
</tfoot>
</table>
30 changes: 18 additions & 12 deletions examples/angular/basic/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Component } from '@angular/core'
import {
ChangeDetectionStrategy,
Component,
type OnInit,
signal,
} from '@angular/core'
import { RouterOutlet } from '@angular/router'
import {
ColumnDef,
FlexRenderDirective,
Table,
createAngularTable,
FlexRenderDirective,
getCoreRowModel,
} from '@tanstack/angular-table'

Expand Down Expand Up @@ -87,16 +91,18 @@ const defaultData: Person[] = [
imports: [RouterOutlet, FlexRenderDirective],
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {
data: Person[] = []
table!: Table<Person>
export class AppComponent implements OnInit {
data = signal<Person[]>([])

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

ngOnInit() {
this.data = [...defaultData]
this.table = createAngularTable({
data: this.data,
columns: defaultColumns,
getCoreRowModel: getCoreRowModel(),
})
this.data.set(defaultData)
}
}
6 changes: 6 additions & 0 deletions examples/angular/grouping/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@
}
}
}
},
"cli": {
"analytics": false,
"cache": {
"enabled": false
}
}
}
128 changes: 64 additions & 64 deletions examples/angular/grouping/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,90 +1,88 @@
<div class="tanstack-table">
<h2>Grouping</h2>
@if (table) {
<table aria-describedby="tanstack table grouping implementation in angular">
<thead>
@for (headerGroup of table.getHeaderGroups(); track headerGroup.id) {
<tr>
@for (header of headerGroup.headers; track header.id) {
<th [attr.colSpan]="header.colSpan">
@if (!header.isPlaceholder && header.column.getCanGroup()) {
<button
id="group-btn"
(click)="header.column.toggleGrouping()"
>
<table aria-describedby="tanstack table grouping implementation in angular">
<thead>
@for (headerGroup of table.getHeaderGroups(); track headerGroup.id) {
<tr>
@for (header of headerGroup.headers; track header.id) {
<th [attr.colSpan]="header.colSpan">
@if (!header.isPlaceholder && header.column.getCanGroup()) {
<button
id="group-btn"
(click)="header.column.toggleGrouping()"
>
<span class="material-icons-sharp">
{{
header.column.getIsGrouped()
? 'remove_circle_outline'
: 'add_circle_outline'
}}
</span>
</button>
<ng-container
*flexRender="
</button>
<ng-container
*flexRender="
header.column.columnDef.header;
props: header.getContext;
let header
"
>
<span>{{ header }}</span>
</ng-container>
}
</th>
}
</tr>
}
</thead>
<tbody>
<ng-container *ngFor="let row of table.getRowModel().rows">
<tr>
@for (cell of row.getVisibleCells(); track cell.id) {
<td>
@if (cell.getIsGrouped()) {
<button (click)="row.toggleExpanded()">
>
<span>{{ header }}</span>
</ng-container>
}
</th>
}
</tr>
}
</thead>
<tbody>
<ng-container *ngFor="let row of table.getRowModel().rows">
<tr>
@for (cell of row.getVisibleCells(); track cell.id) {
<td>
@if (cell.getIsGrouped()) {
<button (click)="row.toggleExpanded()">
<span class="material-icons-sharp">
{{ row.getIsExpanded() ? 'expand_less' : 'expand_more' }}
</span>
</button>
<ng-container
*flexRender="
</button>
<ng-container
*flexRender="
cell.column.columnDef.cell;
props: cell.getContext();
let cell
"
>
<span>{{ cell }}</span>
</ng-container>
} @else if (cell.getIsAggregated()) {
<ng-container
*flexRender="
>
<span>{{ cell }}</span>
</ng-container>
} @else if (cell.getIsAggregated()) {
<ng-container
*flexRender="
cell.column.columnDef.aggregatedCell;
props: cell.getContext();
let aggregatedCell
"
>
{{ aggregatedCell }}
</ng-container>
} @else if (cell.getIsPlaceholder()) {
<span></span>
} @else {
<ng-container
*flexRender="
>
{{ aggregatedCell }}
</ng-container>
} @else if (cell.getIsPlaceholder()) {
<span></span>
} @else {
<ng-container
*flexRender="
cell.column.columnDef.cell;
props: cell.getContext();
let cell
"
>
{{ cell }}
</ng-container>
}
</td>
>
{{ cell }}
</ng-container>
}
</tr>
</ng-container>
</tbody>
</table>
}
</td>
}
</tr>
</ng-container>
</tbody>
</table>

<div class="pagination-container">
<div class="pagination-actions">
Expand Down Expand Up @@ -137,12 +135,14 @@ <h2>Grouping</h2>
class="pagination-select"
(change)="onPageSizeChange($event)"
>
<option
*ngFor="let pageSize of [10, 20, 30, 40, 50]"
[value]="pageSize"
>
Show {{ pageSize }}
</option>
@for (pageSize of [10, 20, 30, 40, 50]; track pageSize) {
<option
[value]="pageSize"
>
Show {{ pageSize }}
</option>
}

</select>
</div>
</div>
Expand Down
Loading