88import { Subscription , fromEvent } from "rxjs" ;
99
1010import { TableModel } from "./table.module" ;
11+ import { TableHeaderItem } from "./table-header-item.class" ;
12+ import { TableItem } from "./table-item.class" ;
1113import { getScrollbarWidth } from "../common/utils" ;
1214import { I18n } from "./../i18n/i18n.module" ;
1315
@@ -165,12 +167,13 @@ import { I18n } from "./../i18n/i18n.module";
165167 [ngClass]="{
166168 'bx--data-table-v2--compact': size === 'sm',
167169 '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
169172 }">
170173 <thead>
171174 <tr>
172175 <th *ngIf="model.hasExpandableRows()"></th>
173- <th *ngIf="showSelectionColumn" style="width: 10px;">
176+ <th *ngIf="!skeleton && showSelectionColumn" style="width: 10px;">
174177 <ibm-checkbox
175178 [size]="size !== ('lg' ? 'sm' : 'md')"
176179 [(ngModel)]="selectAllCheckbox"
@@ -187,6 +190,7 @@ import { I18n } from "./../i18n/i18n.module";
187190 [draggable]="columnsDraggable"
188191 (dragstart)="columnDragStart($event, i)"
189192 (dragend)="columnDragEnd($event, i)">
193+ <span *ngIf="skeleton"></span>
190194 <div
191195 *ngIf="columnsResizable"
192196 class="column-resize-handle"
@@ -215,7 +219,7 @@ import { I18n } from "./../i18n/i18n.module";
215219 </button>
216220 <span
217221 class="bx--table-header-label"
218- *ngIf="this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)">
222+ *ngIf="!skeleton && this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)">
219223 <span *ngIf="!column.template" [title]="column.data">{{column.data}}</span>
220224 <ng-template
221225 [ngTemplateOutlet]="column.template" [ngTemplateOutletContext]="{data: column.data}">
@@ -271,7 +275,7 @@ import { I18n } from "./../i18n/i18n.module";
271275 </div>
272276 </th>
273277 </ng-container>
274- <th [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}">
278+ <th *ngIf="!skeleton" [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}">
275279 <!--
276280 Scrollbar pushes body to the left so this header column is added to push
277281 the title bar the same amount and keep the header and body columns aligned.
@@ -311,7 +315,7 @@ import { I18n } from "./../i18n/i18n.module";
311315 </svg>
312316 </button>
313317 </td>
314- <td *ngIf="showSelectionColumn">
318+ <td *ngIf="!skeleton && showSelectionColumn">
315319 <ibm-checkbox
316320 aria-label="Select row"
317321 [size]="size !== ('lg' ? 'sm' : 'md')"
@@ -364,13 +368,48 @@ import { I18n } from "./../i18n/i18n.module";
364368 `
365369} )
366370export class Table {
371+ /**
372+ * Creates a skeleton model with a row and column count specified by the user
373+ *
374+ * Example:
375+ *
376+ * ```typescript
377+ * this.model = Table.skeletonModel(5, 5);
378+ * ```
379+ *
380+ * @param {number } rowCount
381+ * @param {number } columnCount
382+ */
383+ static skeletonModel ( rowCount : number , columnCount : number ) {
384+ const model = new TableModel ( ) ;
385+ let header = new Array < TableHeaderItem > ( ) ;
386+ let data = new Array < Array < TableItem > > ( ) ;
387+ let row = new Array < TableItem > ( ) ;
388+
389+ for ( let i = 0 ; i < columnCount ; i ++ ) {
390+ header . push ( new TableHeaderItem ( ) ) ;
391+ row . push ( new TableItem ( ) ) ;
392+ }
393+ for ( let i = 0 ; i < rowCount - 1 ; i ++ ) {
394+ data . push ( row ) ;
395+ }
396+
397+ model . header = header ;
398+ model . data = data ;
399+ return model ;
400+ }
401+
367402 /**
368403 * Size of the table rows.
369404 *
370405 * @type {("sm" | "md" | "lg") }
371406 * @memberof Table
372407 */
373408 @Input ( ) size : "sm" | "md" | "lg" = "md" ;
409+ /**
410+ * Set to `true` for a loading table.
411+ */
412+ @Input ( ) skeleton = false ;
374413 /**
375414 * Object of all the strings table needs.
376415 * Defaults to the `TABLE` value from the i18n service.
0 commit comments