This commit is contained in:
Tizian.Breuch
2025-10-24 14:35:07 +02:00
parent 1ec7ac6ccc
commit fd68b47414
16 changed files with 961 additions and 511 deletions

View File

@@ -0,0 +1,53 @@
// /src/app/shared/components/table/generic-table/generic-table.component.ts
import { Component, Input, Output, EventEmitter, SimpleChanges, OnChanges, OnInit } from '@angular/core';
import { CommonModule, CurrencyPipe } from '@angular/common';
import { StatusPillComponent } from '../../ui/status-pill/status-pill.component';
import { ButtonComponent } from '../../ui/button/button.component';
import { PaginatorComponent } from '../paginator/paginator.component';
export type ColumnType = 'text' | 'currency' | 'status' | 'image-text' | 'image' | 'actions';
export interface ColumnConfig {
key: string;
title: string;
type: ColumnType;
imageKey?: string;
subKey?: string;
cssClass?: string;
}
@Component({
selector: 'app-generic-table',
standalone: true,
imports: [ CommonModule, CurrencyPipe, StatusPillComponent, ButtonComponent, PaginatorComponent ],
templateUrl: './generic-table.component.html',
styleUrl: './generic-table.component.css',
})
export class GenericTableComponent implements OnChanges, OnInit {
@Input() data: any[] = [];
@Input() columns: ColumnConfig[] = [];
@Input() itemsPerPage = 10;
@Output() view = new EventEmitter<any>();
@Output() edit = new EventEmitter<any>();
@Output() delete = new EventEmitter<any>();
public displayedData: any[] = [];
public currentPage = 1;
ngOnInit(): void { this.updatePagination(); }
ngOnChanges(changes: SimpleChanges): void { if (changes['data']) { this.currentPage = 1; this.updatePagination(); } }
onPageChange(newPage: number): void { this.currentPage = newPage; this.updatePagination(); }
private updatePagination(): void {
const startIndex = (this.currentPage - 1) * this.itemsPerPage;
const endIndex = startIndex + this.itemsPerPage;
this.displayedData = this.data.slice(startIndex, endIndex);
}
getProperty(item: any, key: string): any {
if (!key) return '';
return key.split('.').reduce((obj, part) => obj && obj[part], item);
}
}