I have an Angular component that shows one or more table rows in a standard html table, like this:
<table>
<thead>
<tr>
<td>Person</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
<td>Total</td>
</tr>
</thead>
<tbody>
<person-row *ngFor="let person of people" ></person-row>
</tbody>
</table>
And then in person-row.component.html:
<tr>
<td>{{person.name}}</td>
<td ngFor="let day of person.available">
{{day}}
</td>
<td>{{sumDays(person.available)}}</td>
</tr>
<tr *ngIf="editMode">
<td> Edit: </td>
<td ngFor="let day of person.available">
<!-- availability toggle checkbox -->
</td>
<td></td>
</tr>
In the parent component scss I direct the browser to ignore the person-row:
person-row {
display: table-row-group;
}
This all nearly works, but the resulting table still puts the whole person-row content into the first column of the table.
| Person | Monday | Tuesday | Wednesday | Thursday | Friday | Total |
|---|---|---|---|---|---|---|
| Alice yes yes no yes no 3 | ||||||
| Bob no yes no no yes 2 | ||||||
| edit [] [x] [] [] [x] [save] | ||||||
| Claire no no yes yes yes 3 |
Note that this is a significant simplification over my existing code to demonstrate the problem, I am aware that in this case the edit row could simply be swapped in place!
Is it possible to show multiple rows using an angular component and have it fit into the existing table formatting, and if so how?
[appPersonRow]and then apply the selector to thetbody. Then you won't have the extra, non-table-compliant markup in the table