Skip to content

Commit f11cf78

Browse files
committed
generate input/output bindings to the GridJS package
1 parent 32c8c23 commit f11cf78

18 files changed

+883
-160
lines changed

‎apps/demo/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"polyfills": ["zone.js"],
1717
"tsConfig": "apps/demo/tsconfig.app.json",
1818
"assets": ["apps/demo/src/favicon.ico", "apps/demo/src/assets"],
19-
"styles": ["apps/demo/src/styles.css"],
19+
"styles": ["node_modules/gridjs/dist/theme/mermaid.min.css"],
2020
"scripts": []
2121
},
2222
"configurations": {

‎apps/demo/src/app/app.component.css

Whitespace-only changes.

‎apps/demo/src/app/app.component.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎apps/demo/src/app/app.component.ts

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,123 @@
11
import { Component } from '@angular/core';
2-
import { RouterModule } from '@angular/router';
32
import { GridJsAngularComponent } from 'gridjs-angular';
4-
import 'gridjs/dist/theme/mermaid.css';
3+
import { TData } from 'gridjs/dist/src/types';
54

65
@Component({
7-
standalone: true,
8-
imports: [GridJsAngularComponent, RouterModule],
96
selector: 'gridjs-angular-root',
10-
templateUrl: './app.component.html',
11-
styleUrl: './app.component.css',
7+
standalone: true,
8+
imports: [GridJsAngularComponent],
9+
template: `<gridjs-angular
10+
[data]="data"
11+
[columns]="columns"
12+
[sort]="true"
13+
[search]="true"
14+
[pagination]="true"
15+
(gridLoad)="onLoad($event)"
16+
(beforeLoad)="onBeforeLoad($event)"
17+
(ready)="onReady($event)"
18+
(cellClick)="onCellClick($event)"
19+
(rowClick)="onRowClick($event)"
20+
></gridjs-angular>`,
1221
})
1322
export class AppComponent {
23+
onLoad = (event: any) => console.log('Grid loaded', event);
24+
onBeforeLoad = (event: any) => console.log('Before grid loaded', event);
25+
onReady = (event: any) => console.log('Grid ready', event);
26+
onCellClick = (event: any) => console.log('Grid cell clicked', event);
27+
onRowClick = (event: any) => console.log('Grid row clicked', event);
28+
1429
columns = ['Name', 'Email', 'Phone Number'];
15-
data = [
16-
['John', 'john@example.com', '(353) 01 222 3333'],
17-
['Mark', 'mark@gmail.com', '(01) 22 888 4444'],
18-
];
30+
data: TData = [
31+
{
32+
name: 'John Doe',
33+
email: 'john.doe@example.com',
34+
phone_number: '555-123-4567',
35+
},
36+
{
37+
name: 'Jane Smith',
38+
email: 'jane.smith@example.com',
39+
phone_number: '555-543-2109',
40+
},
41+
{
42+
name: 'Mike Johnson',
43+
email: 'm.johnson@example.com',
44+
phone_number: '555-987-6543',
45+
},
46+
{
47+
name: 'Sara Lee',
48+
email: 's.lee@example.com',
49+
phone_number: '555-345-6789',
50+
},
51+
{
52+
name: 'William Brown',
53+
email: 'w.brown@example.com',
54+
phone_number: '555-234-5678',
55+
},
56+
{
57+
name: 'Mary White',
58+
email: 'mary.white@example.com',
59+
phone_number: '555-765-4321',
60+
},
61+
{
62+
name: 'Daniel Green',
63+
email: 'd.green@example.com',
64+
phone_number: '555-456-7890',
65+
},
66+
{
67+
name: 'Emma Black',
68+
email: 'emma.black@example.com',
69+
phone_number: '555-876-5432',
70+
},
71+
{
72+
name: 'James Young',
73+
email: 'j.young@example.com',
74+
phone_number: '555-678-9012',
75+
},
76+
{
77+
name: 'Grace Kim',
78+
email: 'grace.kim@example.com',
79+
phone_number: '555-321-0987',
80+
},
81+
{
82+
name: 'Thomas Lee',
83+
email: 'thomas.lee@example.com',
84+
phone_number: '555-901-2345',
85+
},
86+
{
87+
name: 'Elizabeth Davis',
88+
email: 'elizabeth.davis@example.com',
89+
phone_number: '555-432-1098',
90+
},
91+
{
92+
name: 'Michael Harris',
93+
email: 'm.harris@example.com',
94+
phone_number: '555-789-0123',
95+
},
96+
{
97+
name: 'Laura Nguyen',
98+
email: 'laura.nguyen@example.com',
99+
phone_number: '555-234-5678',
100+
},
101+
{
102+
name: 'Kenneth Wilson',
103+
email: 'k.wilson@example.com',
104+
phone_number: '555-678-9012',
105+
},
106+
{
107+
name: 'Nancy Moore',
108+
email: 'nancy.moore@example.com',
109+
phone_number: '555-321-0987',
110+
},
111+
{
112+
name: 'Andrew Taylor',
113+
email: 'andrew.taylor@example.com',
114+
phone_number: '555-901-2345',
115+
},
116+
{
117+
name: 'Steven Thompson',
118+
email: 's.thompson@example.com',
119+
phone_number: '555-432-1098',
120+
},
121+
].map((x) => [x.name, x.email, x.phone_number]);
122+
19123
}

‎apps/demo/src/app/app.config.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎apps/demo/src/app/app.routes.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎apps/demo/src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { bootstrapApplication } from '@angular/platform-browser';
2-
import { appConfig } from './app/app.config';
32
import { AppComponent } from './app/app.component';
43

5-
bootstrapApplication(AppComponent, appConfig).catch((err) =>
4+
bootstrapApplication(AppComponent).catch((err) =>
65
console.error(err)
76
);

‎apps/demo/src/styles.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
"@typescript-eslint/eslint-plugin": "^6.20.0",
5050
"@typescript-eslint/parser": "^6.20.0",
5151
"autoprefixer": "^10.4.17",
52+
"change-case": "^5.4.2",
5253
"eslint": "~8.56.0",
5354
"eslint-config-prettier": "^9.1.0",
5455
"eslint-plugin-playwright": "^0.22.1",
5556
"jest": "^29.7.0",
5657
"jest-environment-jsdom": "^29.7.0",
5758
"jest-preset-angular": "~14.0.0",
5859
"jsonc-eslint-parser": "^2.4.0",
60+
"mustache": "^4.2.0",
5961
"ng-packagr": "~17.1.2",
6062
"nx": "17.3.1",
6163
"postcss": "^8.4.33",

‎packages/gridjs-angular/README.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Angular wrapper for [Grid.js](https://github.com/grid-js/gridjs)
44

5+
[![gridjs-angular repository on GitHub](https://img.shields.io/badge/github-gridjs--angular-green?logo=github&link=https%3A%2F%2Fgithub.com%2Fgrid-js%2Fgridjs-angular)](https://github.com/grid-js/gridjs-angular)
6+
![GridJS peer Dependency Version](https://img.shields.io/npm/dependency-version/gridjs-angular/peer/gridjs)
7+
58
## Install
69

710
```bash
@@ -27,7 +30,7 @@ In your component template
2730

2831
```ts
2932
import { Component } from '@angular/core';
30-
import { UserConfig } from 'gridjs';
33+
import { Config } from 'gridjs';
3134

3235
@Component({
3336
template: `
@@ -41,7 +44,7 @@ import { UserConfig } from 'gridjs';
4144
`
4245
})
4346
class ExampleComponent {
44-
public gridConfig: UserConfig = {
47+
public gridConfig: Config = {
4548
columns: ['Name', 'Email', 'Phone Number'],
4649
data: [
4750
['John', 'john@example.com', '(353) 01 222 3333'],
@@ -70,13 +73,10 @@ class ExampleComponent {
7073
}
7174
```
7275

73-
Finally don't forget to add gridjs theme in your index.html
76+
Finally don't forget to add gridjs theme to your `angular.json` file, or import it some other way.
7477

75-
```html
76-
<link
77-
href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css"
78-
rel="stylesheet"
79-
/>
78+
```json
79+
styles: ["node_modules/gridjs/dist/theme/mermaid.min.css"]
8080
```
8181

8282
## Inputs
@@ -89,7 +89,7 @@ Finally don't forget to add gridjs theme in your index.html
8989

9090
## Outputs
9191

92-
- You can pass all Grid.js events as outputs with a little difference `load` event renamed to `beforeLoad`. See [Grid.js Events](https://gridjs.io/docs/examples/event-handler)
92+
- You can bind to all Grid.js events as outputs. Additionally, the `load` event can also be accessed via `gridLoad` (to avoid conflict with the native DOM `load` event). See [Grid.js Events](https://gridjs.io/docs/examples/event-handler)
9393

9494
### Can I Grid.js rendering helpers? Yes
9595

@@ -114,4 +114,19 @@ Finally don't forget to add gridjs theme in your index.html
114114
}
115115
```
116116

117-
### Can I use Angular components in plugins, formatters, etc? Not yet
117+
### Can I use Angular template syntax in plugins, formatters, etc?
118+
119+
Not currently.
120+
121+
You can't use Angular template syntax in Grid.js plugins, formatters, etc. because they cannot be connected to Angular's change detection system. You can use `h` function or `html` function to create custom HTML for your grid.
122+
123+
## Development
124+
125+
The `gridjs-angular` repository is a monorepo that uses [Nx](https://nx.dev) and [pnpm](https://pnpm.io/).
126+
127+
### Useful commands
128+
129+
- `pnpm install` - Install all dependencies
130+
- `nx serve demo` - Run demo app
131+
- `nx migrate latest` - Update Nx to the latest version, and upgrade all packages from package.json to their latest version
132+
- `nx update-bindings gridjs-angular` - Update the input and output bindings from GridJS to the Angular component. This command should be run after updating the GridJS version.

‎packages/gridjs-angular/project.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
},
3232
"lint": {
3333
"executor": "@nx/eslint:lint"
34+
},
35+
"update-bindings": {
36+
"executor": "nx:run-commands",
37+
"outputs": ["{workspaceRoot}/packages/gridjs-angular/src/lib/gridjs-binding-base.ts"],
38+
"options": {
39+
"command": "node scripts/update-bindings.mjs"
40+
}
3441
}
3542
}
3643
}

‎packages/gridjs-angular/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './lib/constants';
21
export * from './lib/gridjs-angular.component';
2+
export { GRID_EVENTS as GRID_JS_EVENTS } from './lib/gridjs-binding-base';

‎packages/gridjs-angular/src/lib/constants.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)