Last active
September 18, 2018 20:55
-
-
Save danielkuhlwein/16bf5e89a52ea190c016cd3c1f554b21 to your computer and use it in GitHub Desktop.
Data Table Sub Header Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@Component({ | |
... | |
animations: [ | |
trigger('detailExpand', [ | |
state('collapsed', style({ height: '0px', borderBottomWidth: '0px', minHeight: '0', visibility: 'hidden', opacity: 0 })), | |
state('expanded', style({ height: '*', visibility: 'visible', opacity: 1 })), | |
transition('expanded <=> collapsed', animate('55ms cubic-bezier(0.4, 0.0, 0.2, 1)')), | |
transition('collapsed <=> expanded', animate('325ms cubic-bezier(0.4, 0.0, 0.2, 1)')), | |
]), | |
], | |
}) | |
export class DataTableSubHeaderComponent implements OnInit { | |
... | |
headerRowSection: string; | |
currentRow: any; | |
headerExpanded = true; | |
... | |
ngOnInit() { | |
this.dataSource.paginator = this.paginator; | |
} | |
selectRow(event: any, row: any, policy: WorkerPolicy) { | |
this.currentRow = row; | |
if (policy.isHeader) { | |
this.dataSource.data.forEach(currentrow => this.toggleExpansion(currentrow, policy)); | |
} else { | |
// navigate to details | |
} | |
} | |
toggleHeaders() { | |
this.dataSource.data.forEach(row => { | |
this.toggleExpansionByHeader(row, row); | |
}); | |
this.headerExpanded = !this.headerExpanded; | |
} | |
toggleExpansion(row: WorkerPolicy, policy: WorkerPolicy) { | |
if (policy.isHeader) { | |
this.headerRowSection = policy.headerSection; | |
} | |
if (!row.isHeader && row.expanded) { | |
if (row.headerSection === this.headerRowSection) { | |
row.expanded = false; | |
} | |
} else if (!row.isHeader && !row.expanded) { | |
if (row.headerSection === this.headerRowSection) { | |
row.expanded = true; | |
} | |
} else if (row.isHeader && row.headerSection === this.headerRowSection) { | |
row.expanded = !row.expanded; | |
} | |
} | |
toggleExpansionByHeader(row: WorkerPolicy, policy: WorkerPolicy) { | |
if (policy.isHeader) { | |
this.headerRowSection = policy.headerSection; | |
} | |
if (!row.isHeader) { | |
if (row.headerSection === this.headerRowSection) { | |
row.expanded = !this.headerExpanded; | |
} | |
} else if (row.isHeader && row.headerSection === this.headerRowSection) { | |
row.expanded = !this.headerExpanded; | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment