forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk/table): add directive to enable recycle view repeater (angul…
- Loading branch information
1 parent
878c86a
commit 1ff1f88
Showing
17 changed files
with
252 additions
and
13 deletions.
There are no files selected for viewing
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
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
7 changes: 7 additions & 0 deletions
7
src/components-examples/cdk/table/cdk-table-recycle-rows/cdk-table-recycle-rows-example.css
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.example-table { | ||
width: 100%; | ||
} | ||
|
||
.example-row { | ||
text-align: left; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/components-examples/cdk/table/cdk-table-recycle-rows/cdk-table-recycle-rows-example.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<table class="example-table" cdk-table recycleRows [dataSource]="dataSource"> | ||
<!-- Position Column --> | ||
<ng-container cdkColumnDef="position"> | ||
<th class="example-row" cdk-header-cell *cdkHeaderCellDef> No. </th> | ||
<td cdk-cell *cdkCellDef="let element"> {{element.position}} </td> | ||
</ng-container> | ||
|
||
<!-- Name Column --> | ||
<ng-container cdkColumnDef="name"> | ||
<th class="example-row" cdk-header-cell *cdkHeaderCellDef> Name </th> | ||
<td cdk-cell *cdkCellDef="let element"> {{element.name}} </td> | ||
</ng-container> | ||
|
||
<!-- Weight Column --> | ||
<ng-container cdkColumnDef="weight"> | ||
<th class="example-row" cdk-header-cell *cdkHeaderCellDef> Weight </th> | ||
<td cdk-cell *cdkCellDef="let element"> {{element.weight}} </td> | ||
</ng-container> | ||
|
||
<!-- Symbol Column --> | ||
<ng-container cdkColumnDef="symbol"> | ||
<th class="example-row" cdk-header-cell *cdkHeaderCellDef> Symbol </th> | ||
<td cdk-cell *cdkCellDef="let element"> {{element.symbol}} </td> | ||
</ng-container> | ||
|
||
<tr cdk-header-row *cdkHeaderRowDef="displayedColumns"></tr> | ||
<tr cdk-row *cdkRowDef="let row; columns: displayedColumns;"></tr> | ||
</table> |
55 changes: 55 additions & 0 deletions
55
src/components-examples/cdk/table/cdk-table-recycle-rows/cdk-table-recycle-rows-example.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {DataSource} from '@angular/cdk/collections'; | ||
import {Component} from '@angular/core'; | ||
import {BehaviorSubject, Observable} from 'rxjs'; | ||
|
||
export interface PeriodicElement { | ||
name: string; | ||
position: number; | ||
weight: number; | ||
symbol: string; | ||
} | ||
|
||
const ELEMENT_DATA: PeriodicElement[] = [ | ||
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, | ||
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, | ||
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, | ||
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, | ||
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, | ||
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, | ||
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, | ||
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, | ||
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, | ||
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, | ||
]; | ||
|
||
/** | ||
* @title Table that uses the recycle view repeater strategy. | ||
*/ | ||
@Component({ | ||
selector: 'cdk-table-recycle-rows-example', | ||
styleUrls: ['cdk-table-recycle-rows-example.css'], | ||
templateUrl: 'cdk-table-recycle-rows-example.html', | ||
}) | ||
export class CdkTableRecycleRowsExample { | ||
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; | ||
dataSource = new ExampleDataSource(); | ||
} | ||
|
||
/** | ||
* Data source to provide what data should be rendered in the table. Note that the data source | ||
* can retrieve its data in any way. In this case, the data source is provided a reference | ||
* to a common data base, ExampleDatabase. It is not the data source's responsibility to manage | ||
* the underlying data. Instead, it only needs to take the data and send the table exactly what | ||
* should be rendered. | ||
*/ | ||
export class ExampleDataSource extends DataSource<PeriodicElement> { | ||
/** Stream of data that is provided to the table. */ | ||
data = new BehaviorSubject<PeriodicElement[]>(ELEMENT_DATA); | ||
|
||
/** Connect function called by the table to retrieve one stream containing the data to render. */ | ||
connect(): Observable<PeriodicElement[]> { | ||
return this.data; | ||
} | ||
|
||
disconnect() {} | ||
} |
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
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
3 changes: 3 additions & 0 deletions
3
src/components-examples/material/table/table-recycle-rows/table-recycle-rows-example.css
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.example-table { | ||
width: 100%; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/components-examples/material/table/table-recycle-rows/table-recycle-rows-example.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<table class="example-table mat-elevation-z8" mat-table recycleRows [dataSource]="dataSource"> | ||
<!-- Position Column --> | ||
<ng-container matColumnDef="position"> | ||
<th mat-header-cell *matHeaderCellDef> No. </th> | ||
<td mat-cell *matCellDef="let element"> {{element.position}} </td> | ||
</ng-container> | ||
|
||
<!-- Name Column --> | ||
<ng-container matColumnDef="name"> | ||
<th mat-header-cell *matHeaderCellDef> Name </th> | ||
<td mat-cell *matCellDef="let element"> {{element.name}} </td> | ||
</ng-container> | ||
|
||
<!-- Weight Column --> | ||
<ng-container matColumnDef="weight"> | ||
<th mat-header-cell *matHeaderCellDef> Weight </th> | ||
<td mat-cell *matCellDef="let element"> {{element.weight}} </td> | ||
</ng-container> | ||
|
||
<!-- Symbol Column --> | ||
<ng-container matColumnDef="symbol"> | ||
<th mat-header-cell *matHeaderCellDef> Symbol </th> | ||
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td> | ||
</ng-container> | ||
|
||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> | ||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> | ||
</table> | ||
|
34 changes: 34 additions & 0 deletions
34
src/components-examples/material/table/table-recycle-rows/table-recycle-rows-example.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
export interface PeriodicElement { | ||
name: string; | ||
position: number; | ||
weight: number; | ||
symbol: string; | ||
} | ||
|
||
const ELEMENT_DATA: PeriodicElement[] = [ | ||
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, | ||
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, | ||
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, | ||
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, | ||
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, | ||
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, | ||
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, | ||
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, | ||
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, | ||
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, | ||
]; | ||
|
||
/** | ||
* @title Table that uses the recycle view repeater strategy. | ||
*/ | ||
@Component({ | ||
selector: 'table-recycle-rows-example', | ||
styleUrls: ['table-recycle-rows-example.css'], | ||
templateUrl: 'table-recycle-rows-example.html', | ||
}) | ||
export class TableRecycleRowsExample { | ||
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; | ||
dataSource = ELEMENT_DATA; | ||
} |
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
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
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
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
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
Oops, something went wrong.