Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/angular-components/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,28 @@
><ng-container>{{ element[column.property] }}</ng-container>
</ng-container>
<ng-template #htmlBody>
<ng-container
*ngIf="content; else noTemplate"
[ngTemplateOutlet]="content.templateReference"
[ngTemplateOutletContext]="{ rowElement: element }"
></ng-container>
<ng-template #noTemplate><small>No template with DtContent found in datatable body</small></ng-template>
<ng-container *ngIf="contentTemplates.length > 0; else noTemplate">
<ng-container
*ngIf="contentTemplates.length === 1; else multiTemplates"
[ngTemplateOutlet]="contentTemplates[0].template"
[ngTemplateOutletContext]="{ rowElement: element }"
></ng-container>
<ng-template #multiTemplates>
<ng-container
*ngIf="findHtmlTemplate(column.name); else noTemplateWithName"
[ngTemplateOutlet]="findHtmlTemplate(column.name)!.template"
[ngTemplateOutletContext]="{ rowElement: element }"
></ng-container>
</ng-template>
</ng-container>
</ng-template>
</td>
</ng-container>
</ng-container>
<ng-template #noTemplate><small>No template with DtContent found in datatable body</small></ng-template>
<ng-template #noTemplateWithName
><small>No template with DtContent name found in datatable body</small></ng-template
>

<tr cdk-header-row *cdkHeaderRowDef="displayedColumns"></tr>
<tr cdk-row *cdkRowDef="let row; columns: displayedColumns"></tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down Expand Up @@ -48,6 +48,11 @@ export type DataTableServerResponseInfo<T> = {
data: T[];
};

type ContentTemplate<T> = {
template: TemplateRef<DtContent<T>>;
name?: string;
};

@Component({
selector: 'ff-datatable',
standalone: true,
Expand All @@ -59,7 +64,8 @@ export class DatatableComponent<T> implements AfterViewInit, OnDestroy {
@Input({ required: true }) public datasource!: DataTableDataSource<T>;
@Input({ required: true }) public displayColumns: DataTableColumn<T>[] = [];

@ContentChild(DtContentDirective) protected content?: DtContentDirective<T>;
@ContentChildren(DtContentDirective) protected content!: QueryList<DtContentDirective<T>>;
protected contentTemplates: ContentTemplate<T>[] = [];
protected totalFilteredEntries: number = 0;
protected totalEntries: number = 0;
protected minPageEntry: number = 0;
Expand All @@ -76,6 +82,10 @@ export class DatatableComponent<T> 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;
Expand Down Expand Up @@ -107,6 +117,10 @@ export class DatatableComponent<T> implements AfterViewInit, OnDestroy {
updatePage(pageNumber: number): void {
this.datasource.updatePage(pageNumber);
}

protected findHtmlTemplate(templateName: string): ContentTemplate<T> | undefined {
return this.contentTemplates.find(({ name }) => name === templateName);
}
}

export class DataTableDataSource<T> extends DataSource<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Directive, TemplateRef } from '@angular/core';
import { Directive, Input, TemplateRef } from '@angular/core';

export interface DtContent<T> {
rowElement: T;
}

@Directive({
selector: '[appDtContent]',
selector: '[dtContent]',
standalone: true,
})
export class DtContentDirective<T> {
constructor(public templateReference: TemplateRef<DtContent<T>>) {}
@Input() dtContent?: string;
}
3 changes: 2 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ <h2>Chip</h2>
<h2>Datatable</h2>
<div class="components">
<ff-datatable [datasource]="datasource" [displayColumns]="displayedColumns">
<ng-template appDtContent>
<ng-template dtContent="actions">
<span><button>Something</button></span>
</ng-template>
<ng-template dtContent="something"> Something </ng-template>
</ff-datatable>
</div>
<p>Without template:</p>
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down