Reused generic data table for person network tables

This commit is contained in:
Mats Paul Tončik
2026-06-14 12:17:53 +02:00
parent 7f2d0aa6b0
commit 7d7bd87201
22 changed files with 561 additions and 768 deletions
@@ -6,6 +6,7 @@ import {
effect,
input,
output,
signal,
TemplateRef,
viewChild,
} from '@angular/core';
@@ -45,6 +46,14 @@ export type GenericColumn<T> = AccessorColumn<T> | DisplayColumn<T>;
export class DataTableComponent<T> implements AfterViewInit {
data = input.required<T[]>();
columns = input.required<GenericColumn<T>[]>();
filterTerm = input<string>('');
detailTemplate = input<TemplateRef<any> | null>(null);
expandedElement = signal<T | null>(null);
maxHeight = input<string | null>(null);
containerOverflow = computed(() => (this.maxHeight() ? 'auto' : 'visible'));
stickyHeader = input<boolean>(true);
activeSortKey = input<string>('');
sortDirection = input<SortDirection>('');
@@ -72,6 +81,8 @@ export class DataTableComponent<T> implements AfterViewInit {
return value ? String(value).toLowerCase().includes(filter) : false;
});
};
this.dataSource.filter = this.filterTerm().trim().toLowerCase();
});
effect(() => {
@@ -98,4 +109,9 @@ export class DataTableComponent<T> implements AfterViewInit {
onSortChange(sort: Sort) {
this.sortChange.emit(sort);
}
toggleRow(row: T): void {
if (!this.detailTemplate()) return;
this.expandedElement.update((current) => (current === row ? null : row));
}
}