|
8 | 8 | import { Subscription, fromEvent } from "rxjs"; |
9 | 9 |
|
10 | 10 | import { TableModel } from "./table.module"; |
| 11 | +import { TableHeaderItem } from "./table-header-item.class"; |
| 12 | +import { TableItem } from "./table-item.class"; |
11 | 13 | import { getScrollbarWidth } from "../common/utils"; |
12 | 14 | import { I18n } from "./../i18n/i18n.module"; |
13 | 15 |
|
@@ -165,12 +167,13 @@ import { I18n } from "./../i18n/i18n.module"; |
165 | 167 | [ngClass]="{ |
166 | 168 | 'bx--data-table-v2--compact': size === 'sm', |
167 | 169 | 'bx--data-table-v2--tall': size === 'lg', |
168 | | - 'bx--data-table-v2--zebra': striped |
| 170 | + 'bx--data-table-v2--zebra': striped, |
| 171 | + 'bx--skeleton': skeleton |
169 | 172 | }"> |
170 | 173 | <thead> |
171 | 174 | <tr> |
172 | 175 | <th *ngIf="model.hasExpandableRows()"></th> |
173 | | - <th *ngIf="showSelectionColumn" style="width: 10px;"> |
| 176 | + <th *ngIf="!skeleton && showSelectionColumn" style="width: 10px;"> |
174 | 177 | <ibm-checkbox |
175 | 178 | [size]="size !== ('lg' ? 'sm' : 'md')" |
176 | 179 | [(ngModel)]="selectAllCheckbox" |
@@ -215,7 +218,7 @@ import { I18n } from "./../i18n/i18n.module"; |
215 | 218 | </button> |
216 | 219 | <span |
217 | 220 | class="bx--table-header-label" |
218 | | - *ngIf="this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)"> |
| 221 | + *ngIf="!skeleton && this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)"> |
219 | 222 | <span *ngIf="!column.template" [title]="column.data">{{column.data}}</span> |
220 | 223 | <ng-template |
221 | 224 | [ngTemplateOutlet]="column.template" [ngTemplateOutletContext]="{data: column.data}"> |
@@ -271,7 +274,7 @@ import { I18n } from "./../i18n/i18n.module"; |
271 | 274 | </div> |
272 | 275 | </th> |
273 | 276 | </ng-container> |
274 | | - <th [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}"> |
| 277 | + <th *ngIf="!skeleton" [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}"> |
275 | 278 | <!-- |
276 | 279 | Scrollbar pushes body to the left so this header column is added to push |
277 | 280 | the title bar the same amount and keep the header and body columns aligned. |
@@ -311,19 +314,20 @@ import { I18n } from "./../i18n/i18n.module"; |
311 | 314 | </svg> |
312 | 315 | </button> |
313 | 316 | </td> |
314 | | - <td *ngIf="showSelectionColumn"> |
| 317 | + <td *ngIf="!skeleton && showSelectionColumn"> |
315 | 318 | <ibm-checkbox |
316 | 319 | aria-label="Select row" |
317 | 320 | [size]="size !== ('lg' ? 'sm' : 'md')" |
318 | 321 | [(ngModel)]="model.rowsSelected[i]" |
319 | 322 | (change)="onRowCheckboxChange(i)"> |
320 | 323 | </ibm-checkbox> |
321 | 324 | </td> |
322 | | - <ng-container *ngFor="let item of row; let i = index"> |
323 | | - <td *ngIf="model.header[i].visible" |
324 | | - [class]="model.header[i].className" |
325 | | - [ngStyle]="model.header[i].style"> |
| 325 | + <ng-container *ngFor="let item of row; let j = index"> |
| 326 | + <td *ngIf="model.header[j].visible" |
| 327 | + [class]="model.header[j].className" |
| 328 | + [ngStyle]="model.header[j].style"> |
326 | 329 | <ng-container *ngIf="!item.template">{{item.data}}</ng-container> |
| 330 | + <span *ngIf="skeleton && i === 0"></span> |
327 | 331 | <ng-template |
328 | 332 | [ngTemplateOutlet]="item.template" [ngTemplateOutletContext]="{data: item.data}"> |
329 | 333 | </ng-template> |
@@ -364,13 +368,42 @@ import { I18n } from "./../i18n/i18n.module"; |
364 | 368 | ` |
365 | 369 | }) |
366 | 370 | export class Table { |
| 371 | + /** |
| 372 | + * Creates a skeleton model with a row and column count specified by the user |
| 373 | + * |
| 374 | + * @param {number} rowCount |
| 375 | + * @param {number} columnCount |
| 376 | + */ |
| 377 | + static skeletonModelHeader(rowCount: number, columnCount: number) { |
| 378 | + const model = new TableModel(); |
| 379 | + let header = new Array<TableHeaderItem>(); |
| 380 | + let data = new Array<Array<TableItem>>(); |
| 381 | + let row = new Array<TableItem>(); |
| 382 | + |
| 383 | + for (let i = 0; i < columnCount; i++) { |
| 384 | + header.push(new TableHeaderItem()); |
| 385 | + row.push(new TableItem()); |
| 386 | + } |
| 387 | + for (let j = 0; j < rowCount - 1 ; j++) { |
| 388 | + data.push(row); |
| 389 | + } |
| 390 | + |
| 391 | + model.header = header; |
| 392 | + model.data = data; |
| 393 | + return model; |
| 394 | + } |
| 395 | + |
367 | 396 | /** |
368 | 397 | * Size of the table rows. |
369 | 398 | * |
370 | 399 | * @type {("sm" | "md" | "lg")} |
371 | 400 | * @memberof Table |
372 | 401 | */ |
373 | 402 | @Input() size: "sm" | "md" | "lg" = "md"; |
| 403 | + /** |
| 404 | + * Set to `true` for a loading table. |
| 405 | + */ |
| 406 | + @Input() skeleton = false; |
374 | 407 | /** |
375 | 408 | * Object of all the strings table needs. |
376 | 409 | * Defaults to the `TABLE` value from the i18n service. |
|
0 commit comments