diff --git a/projects/angular-components/package.json b/projects/angular-components/package.json index 030a532..dbaa242 100644 --- a/projects/angular-components/package.json +++ b/projects/angular-components/package.json @@ -1,6 +1,6 @@ { "name": "@frankframework/angular-components", - "version": "1.0.2", + "version": "1.1.0", "description": "A collection of reusable components designed for use in Frank!Framework projects", "main": "", "author": "Vivy Booman", diff --git a/projects/angular-components/src/lib/datatable/datatable.component.html b/projects/angular-components/src/lib/datatable/datatable.component.html index af07c6a..112deaf 100644 --- a/projects/angular-components/src/lib/datatable/datatable.component.html +++ b/projects/angular-components/src/lib/datatable/datatable.component.html @@ -29,16 +29,28 @@ >{{ element[column.property] }} - - No template with DtContent found in datatable body + + + + + + + No template with DtContent found in datatable body + No template with DtContent name found in datatable body diff --git a/projects/angular-components/src/lib/datatable/datatable.component.ts b/projects/angular-components/src/lib/datatable/datatable.component.ts index 9acc0a6..b7e8aad 100644 --- a/projects/angular-components/src/lib/datatable/datatable.component.ts +++ b/projects/angular-components/src/lib/datatable/datatable.component.ts @@ -1,9 +1,9 @@ -import { AfterViewInit, Component, ContentChild, Input, OnDestroy } from '@angular/core'; +import { AfterViewInit, Component, ContentChildren, Input, OnDestroy, QueryList, TemplateRef } from '@angular/core'; import { CdkTableModule, DataSource } from '@angular/cdk/table'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { BehaviorSubject, Observable, Subscription } from 'rxjs'; -import { DtContentDirective } from './dt-content.directive'; +import { DtContentDirective, DtContent } from './dt-content.directive'; export type TableOptions = { sizeOptions: number[]; @@ -48,6 +48,11 @@ export type DataTableServerResponseInfo = { data: T[]; }; +type ContentTemplate = { + template: TemplateRef>; + name?: string; +}; + @Component({ selector: 'ff-datatable', standalone: true, @@ -59,7 +64,8 @@ export class DatatableComponent implements AfterViewInit, OnDestroy { @Input({ required: true }) public datasource!: DataTableDataSource; @Input({ required: true }) public displayColumns: DataTableColumn[] = []; - @ContentChild(DtContentDirective) protected content?: DtContentDirective; + @ContentChildren(DtContentDirective) protected content!: QueryList>; + protected contentTemplates: ContentTemplate[] = []; protected totalFilteredEntries: number = 0; protected totalEntries: number = 0; protected minPageEntry: number = 0; @@ -76,6 +82,10 @@ export class DatatableComponent implements AfterViewInit, OnDestroy { ngAfterViewInit(): void { // needed to avoid ExpressionChangedAfterItHasBeenCheckedError setTimeout(() => { + this.contentTemplates = this.content.map((contentItem) => ({ + name: contentItem.dtContent, + template: contentItem.templateReference, + })); const entriesSubscription = this.datasource.getEntriesInfo().subscribe((entriesInfo) => { this.totalEntries = entriesInfo.totalEntries; this.totalFilteredEntries = entriesInfo.totalFilteredEntries; @@ -107,6 +117,10 @@ export class DatatableComponent implements AfterViewInit, OnDestroy { updatePage(pageNumber: number): void { this.datasource.updatePage(pageNumber); } + + protected findHtmlTemplate(templateName: string): ContentTemplate | undefined { + return this.contentTemplates.find(({ name }) => name === templateName); + } } export class DataTableDataSource extends DataSource { diff --git a/projects/angular-components/src/lib/datatable/dt-content.directive.ts b/projects/angular-components/src/lib/datatable/dt-content.directive.ts index fbe4fbe..96c700b 100644 --- a/projects/angular-components/src/lib/datatable/dt-content.directive.ts +++ b/projects/angular-components/src/lib/datatable/dt-content.directive.ts @@ -1,13 +1,14 @@ -import { Directive, TemplateRef } from '@angular/core'; +import { Directive, Input, TemplateRef } from '@angular/core'; export interface DtContent { rowElement: T; } @Directive({ - selector: '[appDtContent]', + selector: '[dtContent]', standalone: true, }) export class DtContentDirective { constructor(public templateReference: TemplateRef>) {} + @Input() dtContent?: string; } diff --git a/src/app/app.component.html b/src/app/app.component.html index 8f52c8b..039d0df 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -80,9 +80,10 @@

Chip

Datatable

- + + Something

Without template:

diff --git a/src/app/app.component.ts b/src/app/app.component.ts index a35f411..b681e22 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -26,6 +26,7 @@ export class AppComponent implements OnInit { { name: 'description', displayName: 'Description', property: 'description' }, { name: 'genre', displayName: 'Genre', property: 'genre' }, { name: 'actions', displayName: 'Actions', property: null, html: true }, + { name: 'something', displayName: 'Something', property: null, html: true }, ]; constructor() {}