added navigating options to app-data-table component enabling navigating on click
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
SortDirection,
|
||||
} from '@angular/material/sort';
|
||||
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
export interface BaseColumn<T> {
|
||||
id: string;
|
||||
@@ -57,7 +58,8 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
|
||||
activeSortKey = input<string>('');
|
||||
sortDirection = input<SortDirection>('');
|
||||
|
||||
navigatePrefix=input<string>('');
|
||||
navigateField=input<string>('');
|
||||
sortChange = output<Sort>();
|
||||
|
||||
displayedColumns = computed(() => this.columns().map((col) => col.id));
|
||||
@@ -65,7 +67,7 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
|
||||
sort = viewChild.required(MatSort);
|
||||
|
||||
constructor() {
|
||||
constructor(private router:Router) {
|
||||
effect(() => {
|
||||
const currentData = this.data();
|
||||
|
||||
@@ -110,6 +112,16 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
this.sortChange.emit(sort);
|
||||
}
|
||||
|
||||
navigateToDataField(row: any): void {
|
||||
if (!this.navigatePrefix() || !this.navigateField()) {
|
||||
return;
|
||||
}
|
||||
const value = row[this.navigateField()];
|
||||
if (value != null) {
|
||||
this.router.navigate([this.navigatePrefix(), value]);
|
||||
}
|
||||
}
|
||||
|
||||
toggleRow(row: T): void {
|
||||
if (!this.detailTemplate()) return;
|
||||
this.expandedElement.update((current) => (current === row ? null : row));
|
||||
|
||||
Reference in New Issue
Block a user