|
| 1 | +--- |
| 2 | +id: angular |
| 3 | +title: Angular |
| 4 | +--- |
| 5 | + |
| 6 | +## Install |
| 7 | + |
| 8 | +```bash |
| 9 | +npm install gridjs gridjs-angular |
| 10 | +``` |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +In your module |
| 15 | + |
| 16 | +```ts |
| 17 | +import { GridjsAngularModule } from 'gridjs-angular'; |
| 18 | + |
| 19 | +@NgModule({ |
| 20 | + imports: [CommonModule,GridjsAngularModule], |
| 21 | + declarations: [...], |
| 22 | + exports: [...], |
| 23 | +}) |
| 24 | +export class AppModule {} |
| 25 | +``` |
| 26 | + |
| 27 | +In your component template |
| 28 | + |
| 29 | +```ts |
| 30 | +import { Component } from "@angular/core"; |
| 31 | +import { GridJsConfig } from "gridjs-angular"; |
| 32 | + |
| 33 | +@Component({ |
| 34 | + template: ` |
| 35 | + <gridjs-angular |
| 36 | + [gridConfig]="gridConfig" |
| 37 | + (cellClick)="handleCellClick($event)" |
| 38 | + (rowClick)="handleRowClick($event)" |
| 39 | + (beforeLoad)="handleBeforeLoad($event)" |
| 40 | + (gridLoad)="handleGridLoad($event)" |
| 41 | + ></gridjs-angular> |
| 42 | + `, |
| 43 | +}) |
| 44 | +class ExampleComponent { |
| 45 | + public gridConfig: GridJsConfig = { |
| 46 | + columns: ["Name", "Email", "Phone Number"], |
| 47 | + data: [ |
| 48 | + [ "John", "[email protected]", "(353) 01 222 3333"], |
| 49 | + [ "Mark", "[email protected]", "(01) 22 888 4444"], |
| 50 | + [ "Eoin", "[email protected]", "0097 22 654 00033"], |
| 51 | + [ "Sarah", "[email protected]", "+322 876 1233"], |
| 52 | + [ "Afshin", "[email protected]", "(353) 22 87 8356"], |
| 53 | + ], |
| 54 | + }; |
| 55 | + |
| 56 | + handleCellClick(event: any) { |
| 57 | + console.log("cellClicked", event); |
| 58 | + } |
| 59 | + |
| 60 | + handleRowClick(event: any) { |
| 61 | + console.log("rowClicked", event); |
| 62 | + } |
| 63 | + |
| 64 | + handleBeforeLoad(event: any) { |
| 65 | + console.log("beforeLoad", event); |
| 66 | + } |
| 67 | + |
| 68 | + handleGridLoad(event: any) { |
| 69 | + console.log("load", event); |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +Finally don't forget to add gridjs theme in your index.html |
| 75 | + |
| 76 | +```html |
| 77 | +<link |
| 78 | + href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" |
| 79 | + rel="stylesheet" |
| 80 | +/> |
| 81 | +``` |
| 82 | + |
| 83 | +## Inputs |
| 84 | + |
| 85 | +- You can pass all Grid.js configs to the `<gridjs-angular>` component as inputs. See [Grid.js Config](https://gridjs.io/docs/config) for more details. |
| 86 | + |
| 87 | +- `gridConfig` You can pass Grid.js config as one object and it will be merged with other Grid.js inputs. |
| 88 | + |
| 89 | +- `plugins` Grid.js plugins array. See [Grid.js Plugins](https://gridjs.io/docs/plugin/basics) |
| 90 | + |
| 91 | +## Outputs |
| 92 | + |
| 93 | +- 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) |
| 94 | + |
| 95 | +### Can I Grid.js rendering helpers? Yes |
| 96 | + |
| 97 | +- Using `h` function is working fine. See this example plugin. |
| 98 | + |
| 99 | +```ts |
| 100 | + { |
| 101 | + id: 'myplugin', |
| 102 | + component: h(() => h('h1', {}, 'Hello world!'), {}), |
| 103 | + position: PluginPosition.Header, |
| 104 | + } |
| 105 | +``` |
| 106 | + |
| 107 | +- You can also use `html` in column formatter like this. |
| 108 | + |
| 109 | +```ts |
| 110 | + { |
| 111 | + name: 'Email', |
| 112 | + formatter: (_, row) => html( |
| 113 | + `<a href='mailto:${row.cells[1].data}'>${row.cells[1].data}</a>` |
| 114 | + ) |
| 115 | + } |
| 116 | +``` |
| 117 | + |
| 118 | +### Can I use Angular components in plugins, formatters, etc? Not yet |
0 commit comments