Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit 7a9f317

Browse files
committed
enable expandable rows for devices list
1 parent 48efea9 commit 7a9f317

File tree

5 files changed

+80
-30
lines changed

5 files changed

+80
-30
lines changed

src/app/lists/device-list/device-list.component.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
<mat-label>Filter</mat-label>
33
<input matInput (keyup)="applyFilter($event)" placeholder="Ex. Up to Date">
44
</mat-form-field>
5-
<table mat-table class="full-width-table" matSort aria-label="Elements">
6-
<!-- Id Column -->
7-
<ng-container matColumnDef="id">
8-
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th>
9-
<td mat-cell *matCellDef="let row">{{row.deviceID}}</td>
5+
<table mat-table class="full-width-table" matSort aria-label="Devices" multiTemplateDataRows>
6+
<ng-container matColumnDef="{{column}}" *ngFor="let column of displayedColumns">
7+
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
8+
<td mat-cell *matCellDef="let device"> {{device[column]}} </td>
109
</ng-container>
11-
12-
<!-- Name Column -->
13-
<ng-container matColumnDef="name">
14-
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
15-
<td mat-cell *matCellDef="let row">{{row.name}}</td>
16-
</ng-container>
17-
18-
<!-- Status Column -->
19-
<ng-container matColumnDef="state">
20-
<th mat-header-cell *matHeaderCellDef mat-sort-header>State</th>
21-
<td mat-cell *matCellDef="let row">{{row.state}}</td>
10+
<ng-container matColumnDef="expandedDetail">
11+
<td mat-cell *matCellDef="let device" [attr.colspan]="displayedColumns.length">
12+
<div class="device-detail" [@detailExpand]="device == expandedDevice ? 'expanded' : 'collapsed'">
13+
<div class="device-folders">
14+
<span>Folders: </span>
15+
<span class="folder-name" *ngFor="let folder of device.folders">{{folder.label | trim}}</span>
16+
</div>
17+
</div>
18+
</td>
2219
</ng-container>
2320

2421
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
25-
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
22+
<tr mat-row *matRowDef="let device; columns: displayedColumns;" class="device-row"
23+
[class.expanded-row]="expandedDevice === device"
24+
(click)="expandedDevice = expandedDevice === device ? null : device">
25+
</tr>
26+
<tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="detail-row"></tr>
2627
</table>
2728

2829
<mat-paginator #paginator [length]="dataSource?.data.length" [pageIndex]="0" [pageSize]="25"
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
.full-width-table {
2-
width: 100%;
2+
width: 100%;
33
}
4-
4+
55
.mat-form-field {
6-
font-size: 14px;
7-
width: 100%;
6+
font-size: 14px;
7+
width: 100%;
8+
}
9+
10+
tr.detail-row {
11+
height: 0;
12+
}
13+
14+
tr.device-row:not(.expanded-row):hover {
15+
background: whitesmoke;
16+
}
17+
18+
/*
19+
tr.device-row:not(.device-row):active {
20+
background: #efefef;
21+
}
22+
*/
23+
24+
.device-row td {
25+
border-bottom-width: 0;
26+
}
27+
28+
.device-detail {
29+
overflow: hidden;
30+
display: flex;
31+
}
32+
33+
.device-folders {
34+
padding-bottom: 16px;
35+
}
36+
37+
// Hide empty name
38+
.folder-name:empty {
39+
display: none;
40+
}
41+
42+
.folder-name:not(:last-child):after {
43+
content: ", ";
844
}

src/app/lists/device-list/device-list.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ import { FilterService } from 'src/app/services/filter.service';
99
import { StType } from 'src/app/type';
1010
import { MatInput } from '@angular/material/input';
1111
import { DeviceService } from 'src/app/services/device.service';
12+
import { trigger, state, style, transition, animate } from '@angular/animations';
1213

1314
@Component({
1415
selector: 'app-device-list',
1516
templateUrl: './device-list.component.html',
16-
styleUrls: ['./device-list.component.scss']
17+
styleUrls: ['./device-list.component.scss'],
18+
animations: [
19+
trigger('detailExpand', [
20+
state('collapsed', style({ height: '0px', minHeight: '0' })),
21+
state('expanded', style({ height: '*' })),
22+
transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
23+
]),
24+
],
1725
})
1826
export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy {
1927
@ViewChild(MatPaginator) paginator: MatPaginator;
@@ -23,7 +31,8 @@ export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy {
2331
dataSource: MatTableDataSource<Device>;
2432

2533
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
26-
displayedColumns = ['id', 'name', 'state'];
34+
displayedColumns = ['deviceID', 'name', 'state'];
35+
expandedDevice: Device | null;
2736

2837
constructor(
2938
private deviceService: DeviceService,

src/app/lists/folder-list/folder-list.component.scss

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ tr.detail-row {
1111
height: 0;
1212
}
1313

14-
tr.folder-row:not(.example-expanded-row):hover {
14+
tr.folder-row:not(.expanded-row):hover {
1515
background: whitesmoke;
1616
}
1717

18+
/*
1819
tr.folder-row:not(.folder-row):active {
1920
background: #efefef;
2021
}
22+
*/
2123

2224
.folder-row td {
2325
border-bottom-width: 0;
@@ -32,15 +34,11 @@ tr.folder-row:not(.folder-row):active {
3234
padding-bottom: 16px;
3335
}
3436

35-
.device-name:not(:first-child) {
36-
margin-left: -.3em;
37-
}
38-
3937
// Hide empty name
4038
.device-name:empty {
4139
display: none;
4240
}
4341

44-
.device-name:not(:first-child):before {
42+
.device-name:not(:last-child):after {
4543
content: ", ";
4644
}

src/app/lists/folder-list/folder-list.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export class FolderListComponent implements AfterViewInit, OnInit, OnDestroy {
3131
dataSource: MatTableDataSource<Folder>;
3232

3333
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
34-
displayedColumns = ['id', 'label', 'path', 'state'];
34+
displayedColumns = [
35+
"id",
36+
"label",
37+
"path",
38+
"state"
39+
];
40+
3541
expandedFolder: Folder | null;
3642

3743
constructor(

0 commit comments

Comments
 (0)