Skip to content

Commit ebe676b

Browse files
Merge pull request #182 from joeskeen/dynamic-bindings
generate input/output bindings to the GridJS package
2 parents 32c8c23 + e7a3d6e commit ebe676b

19 files changed

+791
-162
lines changed

apps/demo/project.json

+1-1
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

-2
This file was deleted.

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

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
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 { faker } from '@faker-js/faker';
4+
import { TData } from 'gridjs/dist/src/types';
55

66
@Component({
7-
standalone: true,
8-
imports: [GridJsAngularComponent, RouterModule],
97
selector: 'gridjs-angular-root',
10-
templateUrl: './app.component.html',
11-
styleUrl: './app.component.css',
8+
standalone: true,
9+
imports: [GridJsAngularComponent],
10+
template: `<gridjs-angular
11+
[data]="data"
12+
[columns]="columns"
13+
[sort]="true"
14+
[search]="true"
15+
[pagination]="true"
16+
(gridLoad)="onLoad($event)"
17+
(beforeLoad)="onBeforeLoad($event)"
18+
(ready)="onReady($event)"
19+
(cellClick)="onCellClick($event)"
20+
(rowClick)="onRowClick($event)"
21+
></gridjs-angular>`,
1222
})
1323
export class AppComponent {
24+
onLoad = (event: any) => console.log('Grid loaded', event);
25+
onBeforeLoad = (event: any) => console.log('Before grid loaded', event);
26+
onReady = (event: any) => console.log('Grid ready', event);
27+
onCellClick = (event: any) => console.log('Grid cell clicked', event);
28+
onRowClick = (event: any) => console.log('Grid row clicked', event);
29+
1430
columns = ['Name', 'Email', 'Phone Number'];
15-
data = [
16-
['John', '[email protected]', '(353) 01 222 3333'],
17-
['Mark', '[email protected]', '(01) 22 888 4444'],
18-
];
31+
data: TData = new Array(20)
32+
.fill(undefined)
33+
.map(() => [
34+
faker.person.fullName(),
35+
faker.internet.email(),
36+
faker.phone.number(),
37+
]);
1938
}

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

-7
This file was deleted.

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

-3
This file was deleted.

apps/demo/src/main.ts

+1-2
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

-1
This file was deleted.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@angular/cli": "~17.1.2",
3333
"@angular/compiler-cli": "~17.1.2",
3434
"@angular/language-service": "~17.1.2",
35+
"@faker-js/faker": "^8.4.0",
3536
"@nx/devkit": "17.3.1",
3637
"@nx/eslint": "17.3.1",
3738
"@nx/eslint-plugin": "17.3.1",
@@ -49,13 +50,15 @@
4950
"@typescript-eslint/eslint-plugin": "^6.20.0",
5051
"@typescript-eslint/parser": "^6.20.0",
5152
"autoprefixer": "^10.4.17",
53+
"change-case": "^5.4.2",
5254
"eslint": "~8.56.0",
5355
"eslint-config-prettier": "^9.1.0",
5456
"eslint-plugin-playwright": "^0.22.1",
5557
"jest": "^29.7.0",
5658
"jest-environment-jsdom": "^29.7.0",
5759
"jest-preset-angular": "~14.0.0",
5860
"jsonc-eslint-parser": "^2.4.0",
61+
"mustache": "^4.2.0",
5962
"ng-packagr": "~17.1.2",
6063
"nx": "17.3.1",
6164
"postcss": "^8.4.33",

packages/gridjs-angular/README.md

+25-10
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', '[email protected]', '(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/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"repository": "https://github.com/grid-js/gridjs-angular",
1515
"license": "MIT",
1616
"peerDependencies": {
17-
"@angular/common": "^17.1.2",
18-
"@angular/core": "^17.1.2",
17+
"@angular/common": ">=17",
18+
"@angular/core": ">=17",
1919
"gridjs": "^6.1.1"
2020
},
2121
"dependencies": {

packages/gridjs-angular/project.json

+7
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

+1-1
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

-35
This file was deleted.

0 commit comments

Comments
 (0)