import { Component, EventEmitter, inject, Output } from '@angular/core';
import { ResultsService } from '../../helpers/results.service';
import { Results } from '../../helpers/results.model';
import { TableModule } from 'primeng/table';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-results-table',
standalone: true,
imports: [TableModule, CommonModule],
templateUrl: './results-table.component.html',
styleUrl: './results-table.component.scss'
})
export class ResultsTableComponent {
data: Results[] = [];
@Output() click = new EventEmitter<string>();
private readonly _resultsService = inject(ResultsService);
ngOnInit(): void {
this.data = this._resultsService.getResultsData() as Results[];
}
onClick(item: Results): void {
console.log('Clicked: ', item.grandPrix);
this.click.emit(item.grandPrix);
}
}
<p-table *ngIf="data" [value]="data" [tableStyle]="{ 'min-width': '50rem' }" stripedRows>
<ng-template pTemplate="header">
<tr>
<th>Futam</th>
<th>Dátum</th>
<th>Győztes</th>
<th>Csapat</th>
<th>Körök száma</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-item>
<tr class="result-row" (click)="onClick(item)">
<td>{{ item.grandPrix }}</td>
<td>{{ item.date | date: 'yyyy-MM-dd' }}</td>
<td>{{ item.winner }}</td>
<td>{{ item.team }}</td>
<td>{{ item.laps }}</td>
</tr>
</ng-template>
</p-table>