Skip to content

Commit

Permalink
fix(material/forms): render table header as text
Browse files Browse the repository at this point in the history
  • Loading branch information
sara-re authored and trik committed Oct 21, 2020
1 parent b3eb5e7 commit 3240bfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/material/forms/table-field.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe('ajf-table-field', () => {
expect(await cells[8].getText()).toBe('Row 2');
});

it('should show table header', async () => {
const cells = await element.all(by.tagName('td')).getWebElements();
cells.forEach(async cell => console.log(await cell.getText()));
expect(await cells[1].getText()).toBe('Label 1');
expect(await cells[2].getText()).toBe('Label 2');
expect(await cells[3].getText()).toBe('Label 3');
});

it('should show an input on data cell click', async () => {
const cells = await element.all(by.tagName('td')).getWebElements();
await cells[0].click();
Expand Down
28 changes: 16 additions & 12 deletions src/material/forms/table-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
</td>
<ng-container *ngIf="columns.length > 1">
<td *ngFor="let c of columns[1]; let column = index">
<ng-container *ngIf="c|ajfGetTableCellControl as contr">
<ng-container *ngIf="contr != null">
<input *ngIf="row > 0 && contr!.show && (node.rows[row-1][column]|ajfIsCellEditable); else plainTextCell"
(focusout)="contr!.show = false" type="number" [formControl]="contr.control"
(keydown.tab)="goToNextCell($event, row, column)" autoFocus>
<ng-template #plainTextCell>
<span *ngIf="row > 0; else labelCell" class="ajf-table-cell"
(click)="goToCell(row, column)">{{ contr.control!.value | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</span>
<ng-template #labelCell>{{ contr | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</ng-template>
</ng-template>
</ng-container>
<ng-container *ngIf="row == 0; else controlCell">
{{ c | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}
</ng-container>
<ng-template #controlCell>
<ng-container *ngIf="c|ajfGetTableCellControl as contr">
<ng-container *ngIf="contr != null">
<input *ngIf="contr!.show && (node.rows[row-1][column]|ajfIsCellEditable); else plainTextCell"
(focusout)="contr!.show = false" type="number" [formControl]="contr.control"
(keydown.tab)="goToNextCell($event, row, column)" autoFocus>
<ng-template #plainTextCell>
<span class="ajf-table-cell"
(click)="goToCell(row, column)">{{ contr.control!.value | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</span>
</ng-template>
</ng-container>
</ng-container>
</ng-template>
</td>
</ng-container>
</tr>
</ng-container>
</ng-container>
</table>
</table>

0 comments on commit 3240bfc

Please sign in to comment.