Reused generic data table for person network tables
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user