From 7e1ff20069cde06969d4e625370fc6b6f5c4e59c Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Thu, 18 May 2023 10:19:46 +0200 Subject: [PATCH] Update datatable.component.md documentation (#8525) --- docs/core/components/datatable.component.md | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/docs/core/components/datatable.component.md b/docs/core/components/datatable.component.md index d32156951b..5eae5ddc43 100644 --- a/docs/core/components/datatable.component.md +++ b/docs/core/components/datatable.component.md @@ -18,6 +18,7 @@ See it live: [DataTable Quickstart](https://embed.plnkr.co/80qr4YFBeHjLMdAV0F6l/ - [Basic usage](#basic-usage) - [Setting the rows and column schema](#setting-the-rows-and-column-schema) - [Transclusions](#transclusions) + - [Row Update](#row-update) - [Class members](#class-members) - [Properties](#properties) - [Events](#events) @@ -247,6 +248,59 @@ export class DataTableDemo { ``` +### Row Update + +Starting with v6.0.0, you need to provide a [`DataTableService`](../../lib/core/src/lib/datatable/services/datatable.service.ts) to update a row of your table. +The model to update the DataTable require the `id` of the row that is being changed, and the new data Object of the row: + +```typescript +interface DataRowUpdateModel { + obj: any; + id: string; +} +``` + +For example, if your table use entry nodes you can pass: + +```typescript +this.dataTableService.rowUpdate.next({ + id: node.id, + obj: { + entry: node + } +}); +``` + +As good practice, it is suggested to provide a [`DataTableService`](../../lib/core/src/lib/datatable/services/datatable.service.ts) at the component level: + +```typescript +@Component({ + selector: 'app-files-component', + templateUrl: './files.component.html', + styleUrls: ['./files.component.scss'], + encapsulation: ViewEncapsulation.None, + providers: [ + DataTableService + ] +}) +export class FilesComponent implements OnInit { + constructor(private dataTableService: DataTableService, + private nodeService: NodesApiService) { + } + + ngOnInit() { + this.nodeService.nodeUpdated.subscribe((node) => { + this.dataTableService.rowUpdate.next({ + id: node.id, + obj: { + entry: node + } + }); + }); + } +} +``` + ### [Transclusions](../../user-guide/transclusion.md) You can add [Data column component](data-column.component.md) instances to define columns for thetable as described in the usage examples and the [Customizing columns](#customizing-columns) section.