Skip to content

Commit 8661db3

Browse files
committed
add editable cell example
1 parent 0caf695 commit 8661db3

23 files changed

+851
-91
lines changed

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,46 @@
6161
</tfoot>
6262
</table>
6363

64-
<div class="h-4"></div>
65-
<button (click)="rerender()" class="border p-2">Rerender</button>
64+
<div class="h-2"></div>
65+
<div class="flex items-center gap-2">
66+
<button
67+
class="border rounded p-1"
68+
(click)="table.setPageIndex(0)"
69+
[disabled]="!table.getCanPreviousPage()"
70+
>
71+
<<
72+
</button>
73+
<button
74+
class="border rounded p-1"
75+
(click)="table.previousPage()"
76+
[disabled]="!table.getCanPreviousPage()"
77+
>
78+
<
79+
</button>
80+
<button
81+
class="border rounded p-1"
82+
(click)="table.nextPage()"
83+
[disabled]="!table.getCanNextPage()"
84+
>
85+
>
86+
</button>
87+
<button
88+
class="border rounded p-1"
89+
(click)="table.setPageIndex(table.getPageCount() - 1)"
90+
[disabled]="!table.getCanNextPage()"
91+
>
92+
>>
93+
</button>
94+
<span class="flex items-center gap-1">
95+
<div>Page</div>
96+
<strong>
97+
{{ table.getState().pagination.pageIndex + 1 }} of
98+
{{ table.getPageCount() }}
99+
</strong>
100+
</span>
101+
</div>
102+
<br />
66103
</div>
104+
<hr />
105+
<br />
106+
<div></div>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FlexRenderDirective,
77
getCoreRowModel,
88
} from '@tanstack/angular-table'
9+
import { FormsModule } from '@angular/forms'
910

1011
type Person = {
1112
firstName: string
@@ -81,7 +82,7 @@ const defaultColumns: ColumnDef<Person>[] = [
8182
@Component({
8283
selector: 'app-root',
8384
standalone: true,
84-
imports: [RouterOutlet, FlexRenderDirective],
85+
imports: [RouterOutlet, FlexRenderDirective, FormsModule],
8586
templateUrl: './app.component.html',
8687
changeDetection: ChangeDetectionStrategy.OnPush,
8788
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "Node.js",
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:18"
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
14+
[*.md]
15+
max_line_length = off
16+
trim_trailing_whitespace = false
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# Visual Studio Code
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
.history/*
30+
31+
# Miscellaneous
32+
/.angular/cache
33+
.sass-cache/
34+
/connect.lock
35+
/coverage
36+
/libpeerconnection.log
37+
testem.log
38+
/typings
39+
40+
# System files
41+
.DS_Store
42+
Thumbs.db
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Basic
2+
3+
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.1.2.
4+
5+
## Development server
6+
7+
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
8+
9+
## Code scaffolding
10+
11+
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12+
13+
## Build
14+
15+
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
16+
17+
## Running unit tests
18+
19+
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20+
21+
## Running end-to-end tests
22+
23+
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
24+
25+
## Further help
26+
27+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"editable": {
7+
"cli": {
8+
"cache": {
9+
"enabled": false
10+
}
11+
},
12+
"projectType": "application",
13+
"schematics": {
14+
"@schematics/angular:component": {
15+
"style": "scss"
16+
}
17+
},
18+
"root": "",
19+
"sourceRoot": "src",
20+
"prefix": "app",
21+
"architect": {
22+
"build": {
23+
"builder": "@angular-devkit/build-angular:application",
24+
"options": {
25+
"outputPath": "dist/editable",
26+
"index": "src/index.html",
27+
"browser": "src/main.ts",
28+
"polyfills": ["zone.js"],
29+
"tsConfig": "tsconfig.app.json",
30+
"inlineStyleLanguage": "scss",
31+
"assets": ["src/favicon.ico", "src/assets"],
32+
"styles": ["src/styles.scss"],
33+
"scripts": []
34+
},
35+
"configurations": {
36+
"production": {
37+
"budgets": [
38+
{
39+
"type": "initial",
40+
"maximumWarning": "500kb",
41+
"maximumError": "1mb"
42+
},
43+
{
44+
"type": "anyComponentStyle",
45+
"maximumWarning": "2kb",
46+
"maximumError": "4kb"
47+
}
48+
],
49+
"outputHashing": "all"
50+
},
51+
"development": {
52+
"optimization": false,
53+
"extractLicenses": false,
54+
"sourceMap": true
55+
}
56+
},
57+
"defaultConfiguration": "production"
58+
},
59+
"serve": {
60+
"builder": "@angular-devkit/build-angular:dev-server",
61+
"configurations": {
62+
"production": {
63+
"buildTarget": "editable:build:production"
64+
},
65+
"development": {
66+
"buildTarget": "editable:build:development"
67+
}
68+
},
69+
"defaultConfiguration": "development"
70+
},
71+
"extract-i18n": {
72+
"builder": "@angular-devkit/build-angular:extract-i18n",
73+
"options": {
74+
"buildTarget": "editable:build"
75+
}
76+
},
77+
"test": {
78+
"builder": "@angular-devkit/build-angular:karma",
79+
"options": {
80+
"polyfills": ["zone.js", "zone.js/testing"],
81+
"tsConfig": "tsconfig.spec.json",
82+
"inlineStyleLanguage": "scss",
83+
"assets": ["src/favicon.ico", "src/assets"],
84+
"styles": ["src/styles.scss"],
85+
"scripts": []
86+
}
87+
}
88+
}
89+
}
90+
},
91+
"cli": {
92+
"analytics": false
93+
}
94+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "tanstack-table-example-angular-basic",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"ng": "ng",
6+
"start": "ng serve",
7+
"build": "ng build",
8+
"watch": "ng build --watch --configuration development",
9+
"test": "ng test"
10+
},
11+
"private": true,
12+
"dependencies": {
13+
"@angular/animations": "^17.3.9",
14+
"@angular/common": "^17.3.9",
15+
"@angular/compiler": "^17.3.9",
16+
"@angular/core": "^17.3.9",
17+
"@angular/forms": "^17.3.9",
18+
"@angular/platform-browser": "^17.3.9",
19+
"@angular/platform-browser-dynamic": "^17.3.9",
20+
"@angular/router": "^17.3.9",
21+
"@tanstack/angular-table": "^8.21.0",
22+
"rxjs": "~7.8.1",
23+
"zone.js": "~0.14.4"
24+
},
25+
"devDependencies": {
26+
"@angular-devkit/build-angular": "^17.3.8",
27+
"@angular/cli": "^17.3.8",
28+
"@angular/compiler-cli": "^17.3.9",
29+
"@types/jasmine": "~5.1.4",
30+
"jasmine-core": "~5.1.2",
31+
"karma": "~6.4.3",
32+
"karma-chrome-launcher": "~3.2.0",
33+
"karma-coverage": "~2.2.1",
34+
"karma-jasmine": "~5.1.0",
35+
"karma-jasmine-html-reporter": "~2.1.0",
36+
"tslib": "^2.6.2",
37+
"typescript": "5.4.5"
38+
}
39+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<div class="p-2">
2+
<table>
3+
<thead>
4+
@for (headerGroup of table.getHeaderGroups(); track headerGroup.id) {
5+
<tr>
6+
@for (header of headerGroup.headers; track header.id) {
7+
@if (!header.isPlaceholder) {
8+
<th>
9+
<ng-container
10+
*flexRender="
11+
header.column.columnDef.header;
12+
props: header.getContext();
13+
let header
14+
"
15+
>
16+
<div [innerHTML]="header"></div>
17+
</ng-container>
18+
</th>
19+
}
20+
}
21+
</tr>
22+
}
23+
</thead>
24+
<tbody>
25+
@for (row of table.getRowModel().rows; track row.id) {
26+
<tr>
27+
@for (cell of row.getVisibleCells(); track cell.id) {
28+
<td>
29+
<ng-container
30+
*flexRender="
31+
cell.column.columnDef.cell;
32+
props: cell.getContext();
33+
let cell
34+
"
35+
>
36+
<div [innerHTML]="cell"></div>
37+
</ng-container>
38+
</td>
39+
}
40+
</tr>
41+
}
42+
</tbody>
43+
<tfoot>
44+
@for (footerGroup of table.getFooterGroups(); track footerGroup.id) {
45+
<tr>
46+
@for (footer of footerGroup.headers; track footer.id) {
47+
<th>
48+
<ng-container
49+
*flexRender="
50+
footer.column.columnDef.footer;
51+
props: footer.getContext();
52+
let footer
53+
"
54+
>
55+
{{ footer }}
56+
</ng-container>
57+
</th>
58+
}
59+
</tr>
60+
}
61+
</tfoot>
62+
</table>
63+
64+
<div class="h-2"></div>
65+
<div class="flex items-center gap-2">
66+
<button
67+
class="border rounded p-1"
68+
(click)="table.setPageIndex(0)"
69+
[disabled]="!table.getCanPreviousPage()"
70+
>
71+
<<
72+
</button>
73+
<button
74+
class="border rounded p-1"
75+
(click)="table.previousPage()"
76+
[disabled]="!table.getCanPreviousPage()"
77+
>
78+
<
79+
</button>
80+
<button
81+
class="border rounded p-1"
82+
(click)="table.nextPage()"
83+
[disabled]="!table.getCanNextPage()"
84+
>
85+
>
86+
</button>
87+
<button
88+
class="border rounded p-1"
89+
(click)="table.setPageIndex(table.getPageCount() - 1)"
90+
[disabled]="!table.getCanNextPage()"
91+
>
92+
>>
93+
</button>
94+
<span class="flex items-center gap-1">
95+
<div>Page</div>
96+
<strong>
97+
{{ table.getState().pagination.pageIndex + 1 }} of
98+
{{ table.getPageCount() }}
99+
</strong>
100+
</span>
101+
</div>
102+
<br />
103+
</div>

0 commit comments

Comments
 (0)