|
1 | 1 | /**
|
2 | 2 | * @license
|
3 |
| - * Copyright Google Inc. All Rights Reserved. |
| 3 | + * Copyright Google LLC All Rights Reserved. |
4 | 4 | *
|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| -import {A11yModule} from '@angular/cdk/a11y'; |
| 8 | + |
9 | 9 | import {Component, NgModule, ViewEncapsulation} from '@angular/core';
|
| 10 | +import {MatTableModule} from '@angular/material/table'; |
10 | 11 | import {BrowserModule} from '@angular/platform-browser';
|
11 | 12 | import {BasicTable, GenericObject} from './basic-table';
|
12 |
| -import {MatTableModule} from '@angular/material/table'; |
13 | 13 |
|
14 |
| -/** |
15 |
| - * @title Checkbox benchmark component. |
16 |
| - */ |
| 14 | +function createRows(numRows: number, cols: string[]): GenericObject[] { |
| 15 | + const rows: GenericObject[] = new Array(numRows); |
| 16 | + for (let i = 0; i < rows.length; i++) { |
| 17 | + rows[i] = createRow(cols, (i + 1).toString()); |
| 18 | + } |
| 19 | + return rows; |
| 20 | +} |
| 21 | + |
| 22 | +function createRow(cols: string[], value: string): GenericObject { |
| 23 | + const row: GenericObject = {}; |
| 24 | + for (let i = 0; i < cols.length; i++) { |
| 25 | + const col = cols[i]; |
| 26 | + row[col] = value; |
| 27 | + } |
| 28 | + return row; |
| 29 | +} |
| 30 | + |
| 31 | +const fiveCols = ['a', 'b', 'c', 'd', 'e']; |
| 32 | +const tenCols = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; |
| 33 | +const twentyCols = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't']; |
| 34 | + |
| 35 | +const tenRows = createRows(10, twentyCols); |
| 36 | +const oneHundredRows = createRows(100, twentyCols); |
| 37 | +const oneThousandRows = createRows(1000, twentyCols); |
| 38 | + |
17 | 39 | @Component({
|
18 | 40 | selector: 'app-root',
|
19 | 41 | template: `
|
20 |
| - <button id="show" (click)="show()">Show</button> |
21 | 42 | <button id="hide" (click)="hide()">Hide</button>
|
| 43 | + <button id="show-10-rows-5-cols" (click)="showTenRowsFiveCols()">Show 10 Rows 5 Cols</button> |
| 44 | + <button id="show-100-rows-5-cols" (click)="showOneHundredRowsFiveCols()">Show 100 Rows 5 Cols</button> |
| 45 | + <button id="show-1000-rows-5-cols" (click)="showOneThousandRowsFiveCols()">Show 1000 Rows 5 Cols</button> |
| 46 | + <button id="show-10-rows-10-cols" (click)="showTenRowsTenCols()">Show 10 Rows 10 Cols</button> |
| 47 | + <button id="show-10-rows-20-cols" (click)="showTenRowsTwentyCols()">Show 10 Rows 20 Cols</button> |
22 | 48 |
|
23 |
| - <button id="ten-rows" (click)="updateTable({ numRows: 10 })">10 Rows</button> |
24 |
| - <button id="one-hundred-rows" (click)="updateTable({ numRows: 100 })">100 Rows</button> |
25 |
| - <button id="one-thousand-rows" (click)="updateTable({ numRows: 1000 })">1000 Rows</button> |
26 |
| -
|
27 |
| - <button id="five-cols" (click)="updateTable({ numCols: 5 })">5 Cols</button> |
28 |
| - <button id="ten-cols" (click)="updateTable({ numCols: 10 })">10 Cols</button> |
29 |
| - <button id="twenty-cols" (click)="updateTable({ numCols: 20 })">20 Cols</button> |
| 49 | + <basic-table [rows]="tenRows" [cols]="fiveCols" *ngIf="isTenRowsFiveColsVisible"></basic-table> |
| 50 | + <basic-table [rows]="oneHundredRows" [cols]="fiveCols" *ngIf="isOneHundredRowsFiveColsVisible"></basic-table> |
| 51 | + <basic-table [rows]="oneThousandRows" [cols]="fiveCols" *ngIf="isOneThousandRowsFiveColsVisible"></basic-table> |
30 | 52 |
|
31 |
| - <ng-container *ngIf="isVisible"> |
32 |
| - <basic-table [rows]="createRows()" [cols]="createCols()"></basic-table> |
33 |
| - </ng-container> |
| 53 | + <basic-table [rows]="tenRows" [cols]="tenCols" *ngIf="isTenRowsTenColsVisible"></basic-table> |
| 54 | + <basic-table [rows]="tenRows" [cols]="twentyCols" *ngIf="isTenRowsTwentyColsVisible"></basic-table> |
34 | 55 | `,
|
35 | 56 | encapsulation: ViewEncapsulation.None,
|
36 | 57 | styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
|
37 | 58 | })
|
38 | 59 | export class TableBenchmarkApp {
|
39 |
| - isVisible = false; |
40 |
| - numRows = 10; |
41 |
| - numCols = 5; |
| 60 | + fiveCols = fiveCols; |
| 61 | + tenCols = tenCols; |
| 62 | + twentyCols = twentyCols; |
42 | 63 |
|
43 |
| - show() { this.isVisible = true; } |
44 |
| - hide() { this.isVisible = false; } |
| 64 | + tenRows = tenRows; |
| 65 | + oneHundredRows = oneHundredRows; |
| 66 | + oneThousandRows = oneThousandRows; |
45 | 67 |
|
46 |
| - /** |
47 |
| - * The cols array is just a string array of size numCols whose values are 0 to numCols. |
48 |
| - */ |
49 |
| - createCols() { |
50 |
| - const cols = new Array(this.numCols); |
51 |
| - for (let i = 0; i < this.numCols; i++) { |
52 |
| - cols[i] = `${i}`; |
53 |
| - } |
54 |
| - return cols; |
55 |
| - } |
| 68 | + isTenRowsFiveColsVisible = false; |
| 69 | + isOneHundredRowsFiveColsVisible = false; |
| 70 | + isOneThousandRowsFiveColsVisible = false; |
| 71 | + isTenRowsTenColsVisible = false; |
| 72 | + isTenRowsTwentyColsVisible = false; |
56 | 73 |
|
57 |
| - /** |
58 |
| - * The rows array is an object array. |
59 |
| - * Each object's keys are the values in the cols array, and the values are "ROW - COL". |
60 |
| - */ |
61 |
| - createRows() { |
62 |
| - const rows = new Array(this.numRows); |
63 |
| - for (let i = 0; i < this.numRows; i++) { |
64 |
| - const row: GenericObject = {}; |
65 |
| - for (let j = 0; j < this.numCols; j++) { |
66 |
| - row[j] = `${i} - ${j}`; |
67 |
| - } |
68 |
| - rows[i] = row; |
69 |
| - } |
70 |
| - return rows; |
| 74 | + hide() { |
| 75 | + this.isTenRowsFiveColsVisible = false; |
| 76 | + this.isOneHundredRowsFiveColsVisible = false; |
| 77 | + this.isOneThousandRowsFiveColsVisible = false; |
| 78 | + this.isTenRowsTenColsVisible = false; |
| 79 | + this.isTenRowsTwentyColsVisible = false; |
71 | 80 | }
|
72 | 81 |
|
73 |
| - /** |
74 |
| - * Sets the number of rows and cols to display in our table. |
75 |
| - * |
76 |
| - * @param param0.numRows The new number of rows to display. |
77 |
| - * @param param0.numCols The new number of cols to display. |
78 |
| - */ |
79 |
| - updateTable({ numRows, numCols }: { numRows?: number, numCols?: number}) { |
80 |
| - if (numRows !== undefined) { this.numRows = numRows; } |
81 |
| - if (numCols !== undefined) { this.numCols = numCols; } |
82 |
| - } |
| 82 | + showTenRowsFiveCols() { this.isTenRowsFiveColsVisible = true; } |
| 83 | + showOneHundredRowsFiveCols() { this.isOneHundredRowsFiveColsVisible = true; } |
| 84 | + showOneThousandRowsFiveCols() { this.isOneThousandRowsFiveColsVisible = true; } |
| 85 | + showTenRowsTenCols() { this.isTenRowsTenColsVisible = true; } |
| 86 | + showTenRowsTwentyCols() { this.isTenRowsTwentyColsVisible = true; } |
83 | 87 | }
|
84 | 88 |
|
85 | 89 |
|
86 | 90 | @NgModule({
|
87 | 91 | declarations: [BasicTable, TableBenchmarkApp],
|
88 | 92 | imports: [
|
89 |
| - A11yModule, |
90 | 93 | BrowserModule,
|
91 | 94 | MatTableModule,
|
92 | 95 | ],
|
93 | 96 | providers: [],
|
94 |
| - bootstrap: [TableBenchmarkApp] |
| 97 | + bootstrap: [TableBenchmarkApp], |
95 | 98 | })
|
96 | 99 | export class AppModule {}
|
0 commit comments