I am having trouble trying to fetch data to my overlay.Where did I go wrong ?
My goal is to fetch from an user array ,data (like cId,logged hours) and display it inside my table.
<button
[disabled]="false"
(click)="op1.show($event)"
pButton
type="button"
class="ui-button-primary"
label="View"
></button>
<p-overlayPanel #op1 [showCloseIcon]="true" [dismissable]="false">
<p-table [value]="day" [style]="{ width: '400px' }" [rows]="5">
<ng-template pTemplate="header">
<tr>
<td class="headerItem">{{ wbsElement }}</td>
<td class="headerItem">{{ saturday }}</td>
<td class="headerItem">{{ sunday }}</td>
...
<td class="headerItem">{{ total }}</td>
</tr>
</ng-template>
<ng-template pTemplate="body" let-day>
<tr>
<td>{{ user.cId }}</td>
<td *ngFor="let day of user.days">{{ day.hoursLogged }}</td>
<td>{{ totalHours }}</td>
</tr>
</ng-template>
</p-table>
</p-overlayPanel>
Above I've got my template that is supposed to create my overlay as shown here
wbsElement = Constants.WBS_ELEMENT;
saturday = Day.SATURDAY;
sunday = Day.SUNDAY;
monday = Day.MONDAY;
...
total = Constants.TOTAL;
user: User;
totalHours: number = 0;
constructor(private configService: ConfigService) {}
ngOnInit() {
this.configService.getUsers().subscribe(users => {
this.user = users[0];
});
this.getTotalHours();
}
private getTotalHours() {
this.user.days.forEach(day => (this.totalHours += day.hoursLogged));
}
This is what I have inside my ts file. user accepts dummy data from the first element of users array. Here's a preview of what it receives:
{
name: "test",
cId: "akaskdasda",
email: "[email protected]",
platformUser: "akakaksda",
days: [
{ weekday: Day.MONDAY, hoursLogged: 5 },
{ weekday: Day.TUESDAY, hoursLogged: 8 },
...
{ weekday: Day.SUNDAY, hoursLogged: 5 }
]
},
Currently ,there's no error is displayed inside console that would help me find out the reason of this behaviour and the output is not desired .
As you can see inside the imgur link , the elements go outside of the table (I dont understand this behaviour). I tried removing my double bindings from table body and printing out random data to see if that would work(I've also removed [value]="day" and let-day when I did this) ,however nothing was shown.Last thing I've tried was replacing ng-template with divs (because essentially that's what they are -as far as my understanding goes) but that didnt go well either.