@angular-generic-table/core 5.0.0-rc.16 → 5.0.0-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/core.component.mjs +334 -39
- package/esm2020/lib/core.module.mjs +5 -1
- package/esm2020/lib/models/gt-pagination.mjs +1 -1
- package/esm2020/lib/models/table-config.interface.mjs +1 -1
- package/esm2020/lib/models/table-events.interface.mjs +1 -1
- package/esm2020/lib/models/table-info.interface.mjs +1 -1
- package/esm2020/lib/pagination/pagination.component.mjs +86 -27
- package/esm2020/lib/pipes/row-selection.pipe.mjs +17 -0
- package/esm2020/lib/utilities/utilities.mjs +36 -1
- package/esm2020/public-api.mjs +8 -1
- package/fesm2015/angular-generic-table-core.mjs +476 -67
- package/fesm2015/angular-generic-table-core.mjs.map +1 -1
- package/fesm2020/angular-generic-table-core.mjs +469 -63
- package/fesm2020/angular-generic-table-core.mjs.map +1 -1
- package/lib/core.component.d.ts +94 -18
- package/lib/core.module.d.ts +5 -4
- package/lib/models/gt-pagination.d.ts +8 -0
- package/lib/models/table-config.interface.d.ts +5 -1
- package/lib/models/table-events.interface.d.ts +11 -2
- package/lib/models/table-info.interface.d.ts +3 -1
- package/lib/pagination/pagination.component.d.ts +49 -11
- package/lib/pipes/row-selection.pipe.d.ts +8 -0
- package/lib/utilities/utilities.d.ts +21 -1
- package/package.json +1 -1
- package/public-api.d.ts +7 -0
- package/scss/index.scss +6 -3
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable, Pipe, Injector, EventEmitter, Component, ChangeDetectionStrategy, Input, Output, NgModule } from '@angular/core';
|
|
3
|
-
import { ReplaySubject, BehaviorSubject, isObservable, of, combineLatest } from 'rxjs';
|
|
3
|
+
import { Subject, ReplaySubject, BehaviorSubject, isObservable, of, combineLatest, fromEvent } from 'rxjs';
|
|
4
|
+
import * as i1 from '@angular/common';
|
|
4
5
|
import { KeyValuePipe, AsyncPipe, NgTemplateOutlet, SlicePipe, NgClass, NgIf, NgForOf, PercentPipe, CommonModule } from '@angular/common';
|
|
5
|
-
import {
|
|
6
|
+
import { distinctUntilChanged, tap, shareReplay, startWith, map, switchMap, withLatestFrom, filter, pluck, take, takeUntil } from 'rxjs/operators';
|
|
6
7
|
|
|
7
8
|
class CoreService {
|
|
8
9
|
constructor() { }
|
|
@@ -153,6 +154,7 @@ let calculate = (data, config) => {
|
|
|
153
154
|
};
|
|
154
155
|
};
|
|
155
156
|
/** sortOnMultipleKeys
|
|
157
|
+
* @description Sort data on multiple keys
|
|
156
158
|
* @param {GtSortOrder} keys - array with sort config objects to sort on, data will be sorted according to array order
|
|
157
159
|
* @returns sort function
|
|
158
160
|
*/
|
|
@@ -169,6 +171,40 @@ const sortOnMultipleKeys = (keys) => {
|
|
|
169
171
|
return 0;
|
|
170
172
|
};
|
|
171
173
|
};
|
|
174
|
+
/** parseSortOrderParams
|
|
175
|
+
* @description Convert sort order query param to array with sort config objects
|
|
176
|
+
* @param sortParams - Query param string where each sort config object is separated by comma and order is indicated by + (ascending) or - (descending), e.g. _'name,-age'_
|
|
177
|
+
* @returns GtSortOrder - Array with sort config objects
|
|
178
|
+
*/
|
|
179
|
+
const parseSortOrderParams = (sortParams) => {
|
|
180
|
+
const sortParamsArray = sortParams.split(',');
|
|
181
|
+
return sortParamsArray.map((sortParam) => {
|
|
182
|
+
const [key, order] = sortParam.split(':');
|
|
183
|
+
return {
|
|
184
|
+
key: key.replace(/^[+-]/, ''),
|
|
185
|
+
order: order === 'desc' ? 'desc' : 'asc',
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
/** sortOrderConfigToParam
|
|
190
|
+
* @description Convert sort config object to string that can be used as query param when sorting is implemented server side
|
|
191
|
+
* @param sortConfig - Sort config object
|
|
192
|
+
* @returns string - Query param string where order is indicated by + (ascending) or - (descending), e.g. _'-name'_
|
|
193
|
+
*/
|
|
194
|
+
const sortOrderConfigToParam = (sortConfig) => {
|
|
195
|
+
const order = sortConfig.order === 'desc' ? '-' : '+';
|
|
196
|
+
return `${order}${sortConfig.key}`;
|
|
197
|
+
};
|
|
198
|
+
/** sortOrderToParams
|
|
199
|
+
* @description Convert sort order array to string that can be used as query param when sorting is implemented server side
|
|
200
|
+
* @param sortOrder - Array with sort config objects
|
|
201
|
+
* @returns string - Query param string where each sort config object is separated by comma and order is indicated by + (ascending) or - (descending), e.g. _'name,-age'_
|
|
202
|
+
*/
|
|
203
|
+
const sortOrderToParams = (sortOrder) => {
|
|
204
|
+
return sortOrder
|
|
205
|
+
.map((sortConfig) => sortOrderConfigToParam(sortConfig))
|
|
206
|
+
.join(',');
|
|
207
|
+
};
|
|
172
208
|
|
|
173
209
|
class CapitalCasePipe {
|
|
174
210
|
transform(s) {
|
|
@@ -309,21 +345,84 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
309
345
|
}]
|
|
310
346
|
}] });
|
|
311
347
|
|
|
348
|
+
class RowSelectionPipe {
|
|
349
|
+
transform(row, selection, comparator, className) {
|
|
350
|
+
return className && comparator(row, selection) ? className : '';
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
RowSelectionPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: RowSelectionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
354
|
+
RowSelectionPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.1.1", ngImport: i0, type: RowSelectionPipe, isStandalone: true, name: "rowSelection" });
|
|
355
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: RowSelectionPipe, decorators: [{
|
|
356
|
+
type: Pipe,
|
|
357
|
+
args: [{
|
|
358
|
+
name: 'rowSelection',
|
|
359
|
+
standalone: true,
|
|
360
|
+
}]
|
|
361
|
+
}] });
|
|
362
|
+
|
|
312
363
|
class CoreComponent {
|
|
313
364
|
constructor() {
|
|
365
|
+
this.unsubscribe$ = new Subject();
|
|
366
|
+
this._navigationKeys = [
|
|
367
|
+
'ArrowDown',
|
|
368
|
+
'ArrowUp',
|
|
369
|
+
'ArrowLeft',
|
|
370
|
+
'ArrowRight',
|
|
371
|
+
'Home',
|
|
372
|
+
'End',
|
|
373
|
+
];
|
|
374
|
+
this._selectKeys = ['Enter', ' '];
|
|
375
|
+
this._customClasses = {
|
|
376
|
+
selectedRow: 'gt-selected',
|
|
377
|
+
activeRow: 'gt-active',
|
|
378
|
+
};
|
|
379
|
+
/** selection
|
|
380
|
+
* @description An object that contains the currently selected row(s) in the table. It's passed to the selection function to determine which rows should be selected.
|
|
381
|
+
* @type {any}
|
|
382
|
+
*/
|
|
383
|
+
this.selection = {};
|
|
384
|
+
/** generateRowId
|
|
385
|
+
* @description Whether or not to generate a unique id for each row in the table. Defaults to `true`.
|
|
386
|
+
* @type {boolean}
|
|
387
|
+
*/
|
|
388
|
+
this.generateRowId = true;
|
|
314
389
|
this.rowClick = new EventEmitter();
|
|
390
|
+
this.rowSelect = new EventEmitter();
|
|
315
391
|
this.sortOrderChange = new EventEmitter();
|
|
316
|
-
this.
|
|
317
|
-
this.
|
|
392
|
+
this._rowActive$ = new ReplaySubject(1);
|
|
393
|
+
this.rowActive = new EventEmitter();
|
|
318
394
|
this.columnSort = new EventEmitter();
|
|
319
|
-
|
|
395
|
+
/** page change event - emitted when current page/index changes for pagination */
|
|
396
|
+
this.pageChange = new EventEmitter();
|
|
397
|
+
this.rowActive$ = this._rowActive$.asObservable().pipe(distinctUntilChanged((p, q) => {
|
|
398
|
+
if (this.rowIdKey && p.row && q.row) {
|
|
399
|
+
return p.row[this.rowIdKey] === q.row[this.rowIdKey];
|
|
400
|
+
}
|
|
401
|
+
else if (this.generateRowId && p.row && q.row) {
|
|
402
|
+
return p.row._id === q.row._id;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
return p.index === q.index;
|
|
406
|
+
}
|
|
407
|
+
}), tap((event) => (this.activeRowIndex = event.index)), tap((event) => this.rowActive.emit(event)), shareReplay(1));
|
|
408
|
+
this.activeRowIndex = null;
|
|
320
409
|
this._loading$ = new ReplaySubject(1);
|
|
321
410
|
this._sortOrder$ = new BehaviorSubject([]);
|
|
322
411
|
this._searchBy$ = new ReplaySubject(1);
|
|
323
412
|
this.searchBy$ = this._searchBy$.pipe(startWith(''), map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
413
|
+
this._pagingInfo$ = new BehaviorSubject({
|
|
414
|
+
pageCurrent: null,
|
|
415
|
+
pageNext: null,
|
|
416
|
+
pagePrevious: null,
|
|
417
|
+
pageSize: null,
|
|
418
|
+
numberOfRecords: null,
|
|
419
|
+
//recordsAfterFilter: null,
|
|
420
|
+
//recordsAfterSearch: null,
|
|
421
|
+
//recordsAll: null,
|
|
422
|
+
});
|
|
324
423
|
// tslint:disable-next-line:variable-name
|
|
325
424
|
this._tableConfig$ = new BehaviorSubject({});
|
|
326
|
-
this.tableConfig$ = this._tableConfig$.pipe(map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
425
|
+
this.tableConfig$ = this._tableConfig$.pipe(map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), tap((config) => (this._tableConfig = config)), shareReplay(1));
|
|
327
426
|
this._data$ = new ReplaySubject(1);
|
|
328
427
|
this.data$ = this._data$.pipe(map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => combineLatest([obs])), withLatestFrom(this.tableConfig$), map(([[data], config]) => {
|
|
329
428
|
// if columns or rows contains config for mapTo...
|
|
@@ -345,31 +444,54 @@ class CoreComponent {
|
|
|
345
444
|
}
|
|
346
445
|
data = newData;
|
|
347
446
|
}
|
|
447
|
+
if (this.generateRowId && !this.rowIdKey && data.length > 0) {
|
|
448
|
+
const dataWithId = [];
|
|
449
|
+
for (let i = 0; i < data.length; i++) {
|
|
450
|
+
dataWithId[i] = Object.assign(Object.assign({}, data[i]), { _id: i });
|
|
451
|
+
}
|
|
452
|
+
data = dataWithId;
|
|
453
|
+
}
|
|
348
454
|
return { data, config };
|
|
349
455
|
}), switchMap((obs) => combineLatest([of(obs), this.sortOrder$, this.searchBy$])), map(([table, sortBy, searchBy]) => {
|
|
350
|
-
var _a, _b, _c;
|
|
456
|
+
var _a, _b, _c, _d, _e;
|
|
351
457
|
// create a new array reference and sort new array (prevent mutating existing state)
|
|
352
458
|
table.data = [...table.data];
|
|
353
|
-
return !sortBy.length || ((_a = table.config) === null || _a === void 0 ? void 0 : _a.disableTableSort)
|
|
354
|
-
? searchBy
|
|
459
|
+
return !(sortBy === null || sortBy === void 0 ? void 0 : sortBy.length) || ((_a = table.config) === null || _a === void 0 ? void 0 : _a.disableTableSort)
|
|
460
|
+
? searchBy && !((_b = this.tableInfo) === null || _b === void 0 ? void 0 : _b.lazyLoaded)
|
|
355
461
|
? search(searchBy, false, table.data, table.config)
|
|
356
462
|
: table.data
|
|
357
|
-
: searchBy
|
|
358
|
-
? (
|
|
359
|
-
: (
|
|
463
|
+
: searchBy && !((_c = this.tableInfo) === null || _c === void 0 ? void 0 : _c.lazyLoaded)
|
|
464
|
+
? (_d = search(searchBy, false, table.data, table.config)) === null || _d === void 0 ? void 0 : _d.sort(sortOnMultipleKeys(sortBy))
|
|
465
|
+
: (_e = table.data) === null || _e === void 0 ? void 0 : _e.sort(sortOnMultipleKeys(sortBy));
|
|
360
466
|
}), shareReplay(1));
|
|
361
467
|
this.calculations$ = combineLatest([this.data$, this.tableConfig$]).pipe(map(([data, config]) => calculate(data, config)), shareReplay(1));
|
|
362
468
|
this.table$ = combineLatest([
|
|
363
469
|
this.data$,
|
|
364
470
|
this.tableConfig$,
|
|
365
|
-
|
|
471
|
+
this._pagingInfo$,
|
|
472
|
+
]).pipe(map(([sorted, config, pagingInfo]) => {
|
|
473
|
+
var _a;
|
|
474
|
+
if (pagingInfo.pageCurrent !== null &&
|
|
475
|
+
pagingInfo.numberOfRecords !== null &&
|
|
476
|
+
pagingInfo.pageSize !== null) {
|
|
477
|
+
return {
|
|
478
|
+
data: [sorted],
|
|
479
|
+
config,
|
|
480
|
+
info: {
|
|
481
|
+
lazyLoaded: true,
|
|
482
|
+
numberOfRecords: pagingInfo.numberOfRecords,
|
|
483
|
+
pageSize: pagingInfo.pageSize,
|
|
484
|
+
pageTotal: (_a = pagingInfo.pageTotal) !== null && _a !== void 0 ? _a : Math.ceil(pagingInfo.numberOfRecords / pagingInfo.pageSize),
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
}
|
|
366
488
|
// if pagination is disabled...
|
|
367
489
|
if (!config.pagination || config.pagination.length === 0) {
|
|
368
490
|
// ...return unaltered array
|
|
369
491
|
return {
|
|
370
492
|
data: [sorted],
|
|
371
493
|
config,
|
|
372
|
-
info: {
|
|
494
|
+
info: { numberOfRecords: sorted.length, pageTotal: 1 },
|
|
373
495
|
};
|
|
374
496
|
}
|
|
375
497
|
// return record set
|
|
@@ -377,20 +499,25 @@ class CoreComponent {
|
|
|
377
499
|
data: chunk(sorted, +(config.pagination.length || 0)),
|
|
378
500
|
config,
|
|
379
501
|
info: {
|
|
380
|
-
|
|
502
|
+
numberOfRecords: sorted.length,
|
|
503
|
+
pageSize: +(config.pagination.length || 0),
|
|
381
504
|
pageTotal: Math.ceil(sorted.length / +(config.pagination.length || 0)),
|
|
382
505
|
},
|
|
383
506
|
};
|
|
384
|
-
}), shareReplay(1));
|
|
385
|
-
this.
|
|
386
|
-
this.
|
|
387
|
-
|
|
507
|
+
}), tap((meta) => this._tableInfo$.next(meta.info)), shareReplay(1));
|
|
508
|
+
this._tableInfo$ = new BehaviorSubject(undefined);
|
|
509
|
+
this._currentPaginationIndex$ = new BehaviorSubject(0);
|
|
510
|
+
this.currentPaginationIndex$ = combineLatest([
|
|
511
|
+
this._currentPaginationIndex$,
|
|
512
|
+
this.table$,
|
|
513
|
+
]).pipe(map(([page, table]) => {
|
|
514
|
+
var _a, _b, _c;
|
|
388
515
|
// determine last page
|
|
389
516
|
const lastPage = Math.ceil(table.info.records /
|
|
390
|
-
(((
|
|
391
|
-
// determine max
|
|
517
|
+
((_a = table.info.recordLength) !== null && _a !== void 0 ? _a : (((_c = (_b = table.config) === null || _b === void 0 ? void 0 : _b.pagination) === null || _c === void 0 ? void 0 : _c.length) || table.info.records))) - 1;
|
|
518
|
+
// determine min/max position
|
|
392
519
|
return +page < 0 ? 0 : +page > lastPage ? lastPage : +page;
|
|
393
|
-
}), shareReplay(1));
|
|
520
|
+
}), distinctUntilChanged(), tap((index) => this.pageChange.emit({ index })), shareReplay(1));
|
|
394
521
|
this.colspan$ = this.tableConfig$.pipe(switchMap((config) => config.columns
|
|
395
522
|
? of(Object.values(config.columns || config.rows || {}).filter((value) => value.hidden !== true).length)
|
|
396
523
|
: this.data$.pipe(map((data) => data.length + 1))), shareReplay(1));
|
|
@@ -408,6 +535,30 @@ class CoreComponent {
|
|
|
408
535
|
this.columnOrder = (a, b) => {
|
|
409
536
|
return (a.value.order || 0) - (b.value.order || 0);
|
|
410
537
|
};
|
|
538
|
+
this._unsubscribeFromKeyboardEvents$ = new Subject();
|
|
539
|
+
this._keyboardArrowEvent$ = fromEvent(document, 'keydown').pipe(filter((event) => [...this._navigationKeys, ...this._selectKeys].indexOf(event.key) > -1));
|
|
540
|
+
}
|
|
541
|
+
get navigationKeys() {
|
|
542
|
+
return this._navigationKeys;
|
|
543
|
+
}
|
|
544
|
+
/** navigationKeys
|
|
545
|
+
* @description An array of keyboard keys that will trigger navigation and active row, currently only supports arrow keys, home and end (omit key name from array to disable it)
|
|
546
|
+
* @type {string[]}
|
|
547
|
+
* @default ['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Home', 'End']
|
|
548
|
+
*/
|
|
549
|
+
set navigationKeys(value) {
|
|
550
|
+
this._navigationKeys = value;
|
|
551
|
+
}
|
|
552
|
+
get selectKeys() {
|
|
553
|
+
return this._selectKeys;
|
|
554
|
+
}
|
|
555
|
+
/** selectKeys
|
|
556
|
+
* @description An array of keyboard keys that will trigger row selection (omit key name from array to disable it)
|
|
557
|
+
* @type {string[]}
|
|
558
|
+
* @default ['Enter', ' ']
|
|
559
|
+
*/
|
|
560
|
+
set selectKeys(value) {
|
|
561
|
+
this._selectKeys = value;
|
|
411
562
|
}
|
|
412
563
|
get sortOrder$() {
|
|
413
564
|
return this._sortOrder$.asObservable();
|
|
@@ -415,8 +566,52 @@ class CoreComponent {
|
|
|
415
566
|
set loading(isLoading) {
|
|
416
567
|
this._loading$.next(isLoading);
|
|
417
568
|
}
|
|
418
|
-
set
|
|
419
|
-
this.
|
|
569
|
+
set paginationIndex(pageIndex) {
|
|
570
|
+
this._currentPaginationIndex$.next(pageIndex);
|
|
571
|
+
}
|
|
572
|
+
get paginationIndex() {
|
|
573
|
+
return this._currentPaginationIndex$.getValue();
|
|
574
|
+
}
|
|
575
|
+
set pagingInfo(value) {
|
|
576
|
+
if (value) {
|
|
577
|
+
this._pagingInfo$.next(value);
|
|
578
|
+
if (value.pageCurrent !== this._currentPaginationIndex$.getValue() + 1 &&
|
|
579
|
+
value.pageCurrent !== null) {
|
|
580
|
+
this.paginationIndex = value.pageCurrent - 1;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/** customClasses
|
|
585
|
+
* @description An object that contains custom classes for various elements in the table.
|
|
586
|
+
* @type {object} - { selectedRow: string, activeRow: string } - default classes are 'gt-selected' and 'gt-active'
|
|
587
|
+
*/
|
|
588
|
+
set customClasses(classes) {
|
|
589
|
+
this._customClasses = Object.assign(Object.assign({}, this._customClasses), classes);
|
|
590
|
+
}
|
|
591
|
+
get customClasses() {
|
|
592
|
+
return this._customClasses;
|
|
593
|
+
}
|
|
594
|
+
/** isRowSelectedFn
|
|
595
|
+
* @description Function to determine if row is selected or not.
|
|
596
|
+
* @type {fn} A function that receives a row object and optional state for current selection that can be used to determine if row should be marked as selected or not. */
|
|
597
|
+
set isRowSelectedFn(fn) {
|
|
598
|
+
this._isRowSelectedFn = fn;
|
|
599
|
+
}
|
|
600
|
+
get isRowSelectedFn() {
|
|
601
|
+
return this._isRowSelectedFn;
|
|
602
|
+
}
|
|
603
|
+
/** trackRowByFn
|
|
604
|
+
* @description A function that returns a unique identifier for each row in the table to optimize rendering when data is added or removed.
|
|
605
|
+
* @type fn - TrackByFunction to retrieve unique id based on index and/or row. Defaults to using `row[this.rowIdKey]`.
|
|
606
|
+
*/
|
|
607
|
+
set trackRowByFn(fn) {
|
|
608
|
+
this._trackRowByFn = fn;
|
|
609
|
+
}
|
|
610
|
+
get trackRowByFn() {
|
|
611
|
+
return this._trackRowByFn;
|
|
612
|
+
}
|
|
613
|
+
_trackRowByFn(index, row) {
|
|
614
|
+
return this.rowIdKey ? row[this.rowIdKey] : row === null || row === void 0 ? void 0 : row._id;
|
|
420
615
|
}
|
|
421
616
|
set search(string) {
|
|
422
617
|
this._searchBy$.next(string);
|
|
@@ -425,7 +620,9 @@ class CoreComponent {
|
|
|
425
620
|
this._tableConfig$.next(config);
|
|
426
621
|
}
|
|
427
622
|
set data(data) {
|
|
428
|
-
|
|
623
|
+
if (data) {
|
|
624
|
+
this._data$.next(data);
|
|
625
|
+
}
|
|
429
626
|
}
|
|
430
627
|
set sortOrder(sortConfig) {
|
|
431
628
|
if (JSON.stringify(sortConfig) !== JSON.stringify(this._sortOrder$.value)) {
|
|
@@ -436,31 +633,45 @@ class CoreComponent {
|
|
|
436
633
|
_rowClick(row, index, event) {
|
|
437
634
|
this.rowClick.emit({ row, index, event });
|
|
438
635
|
}
|
|
439
|
-
|
|
636
|
+
_rowActive(row, index, event) {
|
|
637
|
+
this.rowSelect.emit({ row, index, event });
|
|
638
|
+
}
|
|
639
|
+
activateRow(arg, event) {
|
|
440
640
|
if (typeof arg === 'number') {
|
|
441
|
-
this.
|
|
442
|
-
.pipe(map((data) => data[arg]), take(1))
|
|
443
|
-
.subscribe((row) => this.
|
|
641
|
+
this.table$
|
|
642
|
+
.pipe(pluck('data'), map((data) => data[this.paginationIndex][arg]), take(1), takeUntil(this.unsubscribe$))
|
|
643
|
+
.subscribe((row) => this._activateRow(row, arg, event));
|
|
444
644
|
}
|
|
445
645
|
else if (typeof arg === 'string') {
|
|
446
646
|
// TODO: implement hover by id
|
|
447
647
|
}
|
|
448
648
|
else {
|
|
449
|
-
this.
|
|
649
|
+
this._activateRow(null, null);
|
|
450
650
|
}
|
|
451
651
|
}
|
|
452
|
-
|
|
453
|
-
this.
|
|
652
|
+
_activateRow(row, index, event) {
|
|
653
|
+
this._rowActive$.next({ row, index, event });
|
|
454
654
|
}
|
|
455
655
|
get loading$() {
|
|
456
656
|
return this._loading$.pipe(startWith(false), map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
457
657
|
}
|
|
658
|
+
/** tableInfo$ - returns observable for table info
|
|
659
|
+
* @return Observable<TableInfo> */
|
|
660
|
+
get tableInfo$() {
|
|
661
|
+
return this._tableInfo$.asObservable().pipe(filter((info) => !!info), shareReplay(1));
|
|
662
|
+
}
|
|
663
|
+
/** tableInfo - returns the current table info
|
|
664
|
+
* @return TableInfo */
|
|
665
|
+
get tableInfo() {
|
|
666
|
+
return this._tableInfo$.getValue();
|
|
667
|
+
}
|
|
458
668
|
/** sortByKey - Sort by key in table row
|
|
459
669
|
* @param key - key to sort by
|
|
460
670
|
* @param { MouseEvent } [$event] - Mouse event triggering sort, if shift key is pressed sort key will be added to already present sort keys
|
|
461
671
|
*/
|
|
462
672
|
sortByKey(key, $event) {
|
|
463
|
-
|
|
673
|
+
var _a;
|
|
674
|
+
const shiftKey = ($event === null || $event === void 0 ? void 0 : $event.shiftKey) === true;
|
|
464
675
|
const currentOrder = this._sortOrder$.value;
|
|
465
676
|
let sortOrder = 'asc';
|
|
466
677
|
let newOrder = [];
|
|
@@ -505,6 +716,7 @@ class CoreComponent {
|
|
|
505
716
|
key,
|
|
506
717
|
order: sortOrder,
|
|
507
718
|
currentSortOrder: newOrder,
|
|
719
|
+
addSortKey: shiftKey,
|
|
508
720
|
};
|
|
509
721
|
// if event is passed to sort function...
|
|
510
722
|
if ($event) {
|
|
@@ -513,17 +725,131 @@ class CoreComponent {
|
|
|
513
725
|
}
|
|
514
726
|
// emit sort event
|
|
515
727
|
this.columnSort.emit(sortEvent);
|
|
516
|
-
//
|
|
517
|
-
this.
|
|
728
|
+
// if table is not lazy loaded (sorting is then handled server-side)...
|
|
729
|
+
if (!((_a = this.tableInfo) === null || _a === void 0 ? void 0 : _a.lazyLoaded)) {
|
|
730
|
+
// ...update sort order
|
|
731
|
+
this.sortOrder = newOrder;
|
|
732
|
+
}
|
|
518
733
|
}
|
|
519
734
|
nestedValue(object, mapTo, missingValue = null) {
|
|
520
735
|
const levels = mapTo.split('.');
|
|
521
736
|
return levels.reduce((previousValue, currentValue, index) => previousValue[currentValue] ||
|
|
522
737
|
(index === levels.length - 1 ? missingValue : {}), object);
|
|
523
738
|
}
|
|
739
|
+
listenToKeyboardEvents() {
|
|
740
|
+
var _a;
|
|
741
|
+
if (!((_a = this._tableConfig) === null || _a === void 0 ? void 0 : _a.activateRowOnKeyboardNavigation)) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
this._unsubscribeFromKeyboardEvents$.next(true);
|
|
745
|
+
this._keyboardArrowEvent$
|
|
746
|
+
.pipe(withLatestFrom(this.data$, this.currentPaginationIndex$, this.tableInfo$), takeUntil(this._unsubscribeFromKeyboardEvents$), takeUntil(this.unsubscribe$))
|
|
747
|
+
.subscribe(([event, rows, currentPage, tableInfo]) => {
|
|
748
|
+
var _a;
|
|
749
|
+
const selectEvent = this._selectKeys.includes(event.key);
|
|
750
|
+
if (selectEvent && this.activeRowIndex !== null) {
|
|
751
|
+
const rowIndex = this.activeRowIndex + currentPage * ((_a = tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageSize) !== null && _a !== void 0 ? _a : 0);
|
|
752
|
+
this._rowActive(rows[rowIndex], rowIndex, event);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
const navigationEvent = this._navigationKeys.includes(event.key);
|
|
756
|
+
if (navigationEvent) {
|
|
757
|
+
this._handleNavigationEvent(event, rows, currentPage, tableInfo);
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
unsubscribeFromKeyboardEvents(tableRef) {
|
|
762
|
+
var _a, _b;
|
|
763
|
+
if (!((_a = this._tableConfig) === null || _a === void 0 ? void 0 : _a.activateRowOnKeyboardNavigation)) {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
// only unsubscribe if table is not focused
|
|
767
|
+
if (tableRef !== document.activeElement) {
|
|
768
|
+
if ((_b = this._tableConfig) === null || _b === void 0 ? void 0 : _b.activateRowOnHover) {
|
|
769
|
+
// unset active row
|
|
770
|
+
this.activateRow(null);
|
|
771
|
+
}
|
|
772
|
+
this._unsubscribeFromKeyboardEvents$.next(true);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
_handleNavigationEvent(event, rows, currentPage, tableInfo) {
|
|
776
|
+
const hasPagination = ((tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageTotal) || 0) > 1 && tableInfo;
|
|
777
|
+
const lastRowIndex = rows.length - 1;
|
|
778
|
+
let newIndex = this.activeRowIndex;
|
|
779
|
+
let indexModifier = 0;
|
|
780
|
+
if (event.key === 'Home') {
|
|
781
|
+
this.paginationIndex = 0;
|
|
782
|
+
this.activateRow(0, event);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (event.key === 'End') {
|
|
786
|
+
const indexOfLastRecord = hasPagination
|
|
787
|
+
? rows.length - (tableInfo.pageTotal - 1) * tableInfo.pageSize - 1
|
|
788
|
+
: lastRowIndex;
|
|
789
|
+
if (tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageTotal) {
|
|
790
|
+
this.paginationIndex = tableInfo.pageTotal - 1;
|
|
791
|
+
}
|
|
792
|
+
this.activateRow(indexOfLastRecord, event);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (event.key === 'ArrowDown') {
|
|
796
|
+
indexModifier = 1;
|
|
797
|
+
}
|
|
798
|
+
else if (event.key === 'ArrowUp') {
|
|
799
|
+
indexModifier = -1;
|
|
800
|
+
}
|
|
801
|
+
if (newIndex === null) {
|
|
802
|
+
newIndex = 0;
|
|
803
|
+
}
|
|
804
|
+
else if (newIndex + indexModifier >= 0 &&
|
|
805
|
+
newIndex + indexModifier <= lastRowIndex) {
|
|
806
|
+
newIndex = newIndex + indexModifier;
|
|
807
|
+
}
|
|
808
|
+
if (hasPagination && (tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageSize)) {
|
|
809
|
+
const isNotLastPage = currentPage + 1 < tableInfo.pageTotal;
|
|
810
|
+
const recordsOnLastPage = rows.length - (tableInfo.pageTotal - 1) * tableInfo.pageSize - 1;
|
|
811
|
+
const maxIndex = isNotLastPage
|
|
812
|
+
? (tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageSize) - 1
|
|
813
|
+
: recordsOnLastPage;
|
|
814
|
+
if (event.key === 'ArrowLeft' && currentPage > 0) {
|
|
815
|
+
this.paginationIndex = currentPage - 1;
|
|
816
|
+
this.activateRow(newIndex, event);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
else if (event.key === 'ArrowRight' && isNotLastPage) {
|
|
820
|
+
if (currentPage + 1 === tableInfo.pageTotal - 1 &&
|
|
821
|
+
newIndex > recordsOnLastPage) {
|
|
822
|
+
this.activateRow(recordsOnLastPage, event);
|
|
823
|
+
}
|
|
824
|
+
this.paginationIndex = currentPage + 1;
|
|
825
|
+
this.activateRow(newIndex, event);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (currentPage > 0 &&
|
|
829
|
+
indexModifier < 0 &&
|
|
830
|
+
newIndex + indexModifier <= lastRowIndex &&
|
|
831
|
+
(this.activeRowIndex || 0) + indexModifier < 0) {
|
|
832
|
+
// set last row of previous page as active
|
|
833
|
+
this.activateRow((tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageSize) - 1, event);
|
|
834
|
+
this.paginationIndex = currentPage - 1;
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const pageIndex = newIndex % (tableInfo === null || tableInfo === void 0 ? void 0 : tableInfo.pageSize);
|
|
838
|
+
if (newIndex > maxIndex && currentPage + 1 < tableInfo.pageTotal) {
|
|
839
|
+
this.paginationIndex = currentPage + 1;
|
|
840
|
+
}
|
|
841
|
+
this.activateRow(pageIndex > maxIndex ? maxIndex : pageIndex, event);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
this.activateRow(newIndex, event);
|
|
845
|
+
}
|
|
846
|
+
ngOnDestroy() {
|
|
847
|
+
this.unsubscribe$.next(true);
|
|
848
|
+
this.unsubscribe$.complete();
|
|
849
|
+
}
|
|
524
850
|
}
|
|
525
851
|
CoreComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: CoreComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
526
|
-
CoreComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: CoreComponent, isStandalone: true, selector: "angular-generic-table", inputs: { loading: "loading", page: "page", search: "search", config: "config", data: "data", sortOrder: "sortOrder" }, outputs: { rowClick: "rowClick", sortOrderChange: "sortOrderChange", rowHover: "rowHover", columnSort: "columnSort" }, ngImport: i0, template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortOrder$ | async | sortClass: column.key:'aria'\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n [attr.data-sort-order]=\"\n sortOrder$ | async | sortClass: column.key:'order'\n \"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading ||\n !column.value.sortable ||\n sortByKey(column.key, $event)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"\n sortOrder$ | async | sortClass: headerRow.key:'aria'\n \"\n ngClass=\"{{ headerRow.value.sortable ? 'sort ' : '' }} {{\n sortOrder$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading ||\n !headerRow.value.sortable ||\n sortByKey(headerRow.key, $event)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config.rows || {})[headerRow.key].transform,\n templateRef: (table.config.rows || {})[headerRow.key].templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n <tfoot *ngIf=\"(table$ | async)! as table\">\n <ng-container *ngIf=\"table.data.length > 0 && !(loading$ | async)\">\n <ng-container *ngIf=\"(calculations$ | async)! as calculations\">\n <tr\n *ngFor=\"let calculation of calculations.calculations; let i = index\"\n >\n <ng-container\n *ngIf=\"{\n showHeader: (colspan$ | async) !== (footerColspan$ | async)\n } as footerRow\"\n >\n <th\n *ngIf=\"footerRow.showHeader\"\n [colSpan]=\"\n ((colspan$ | async) || 0) - ((footerColspan$ | async) || 0)\n \"\n scope=\"row\"\n >\n <ng-container\n *ngIf=\"table.config?.footer?.headers?.[calculation] as showHeader\"\n >{{showHeader === true ? (calculation | capitalCase): table.config.footer?.headers?.[calculation]}}\n </ng-container>\n </th>\n <ng-container\n *ngFor=\"\n let column of table.config?.columns | keyvalue: columnOrder\n \"\n >\n <td\n *ngIf=\"\n !column.value?.hidden && calculations.calculated[column.key]\n \"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-header]=\"\n !footerRow.showHeader && table.config.footer?.headers?.[calculation]\n ? table.config.footer?.headers?.[calculation] === true ? (calculation | capitalCase) : table.config.footer?.headers?.[calculation]\n : null\n \"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n [class.gt-no-content]=\"\n !calculations.calculated[column.key][calculation]\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformFooter\n : rawFooter\n \"\n [ngTemplateOutletContext]=\"{\n value: calculations.calculated[column.key][calculation],\n row: calculations.calculated[column.key],\n column: calculation,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n transform: (table.config.columns || {})[column.key]\n .transform\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </ng-container>\n </tr>\n </ng-container>\n </ng-container>\n </tfoot>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![(currentPage$ | async) || 0];\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseover)=\"table?.config?.rowHover && _hoverRow(row, i, $event)\"\n (mouseout)=\"table?.config?.rowHover && _hoverRow(null, null, $event)\"\n [class.gt-hover]=\"(rowHover$ | async)?.index === i\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config.columns || {})[column.key].transform,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseover)=\"table?.config?.rowHover && _hoverRow(row, i, $event)\"\n (mouseout)=\"\n table?.config?.rowHover && _hoverRow(null, null, $event)\n \"\n [class.gt-hover]=\"(rowHover$ | async)?.index === i\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config.rows || {})[row.key].transform,\n templateRef: (table.config.rows || {})[row.key].templateRef,\n index: table.config.rows ? y : i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template\n #highlighted\n let-row=\"row\"\n let-column=\"column\"\n let-search=\"search\"\n let-transform=\"transform\"\n>\n <div\n *ngIf=\"!transform\"\n [innerHTML]=\"row[column.key] | highlight: search\"\n ></div>\n <div\n *ngIf=\"transform\"\n [innerHTML]=\"\n row[column.key]\n | dynamicPipe: transform.pipe:transform?.args\n | highlight: search\n \"\n ></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template #transformFooter let-value=\"value\" let-transform=\"transform\">\n {{\n (value | dynamicPipe: transform.pipe:transform?.args) ||\n (tableConfig$ | async)?.footer?.emptyContent\n }}\n</ng-template>\n<ng-template #rawFooter let-value=\"value\">\n {{ value || (tableConfig$ | async)?.footer?.emptyContent }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n", dependencies: [{ kind: "pipe", type: CapitalCasePipe, name: "capitalCase" }, { kind: "pipe", type: KeyValuePipe, name: "keyvalue" }, { kind: "pipe", type: SortClassPipe, name: "sortClass" }, { kind: "pipe", type: DashCasePipe, name: "dashCase" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: SlicePipe, name: "slice" }, { kind: "pipe", type: DynamicPipe, name: "dynamicPipe" }, { kind: "pipe", type: HighlightPipe, name: "highlight" }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
852
|
+
CoreComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: CoreComponent, isStandalone: true, selector: "angular-generic-table", inputs: { navigationKeys: "navigationKeys", selectKeys: "selectKeys", loading: "loading", paginationIndex: "paginationIndex", pagingInfo: "pagingInfo", customClasses: "customClasses", isRowSelectedFn: "isRowSelectedFn", selection: "selection", rowIdKey: "rowIdKey", generateRowId: "generateRowId", trackRowByFn: "trackRowByFn", search: "search", config: "config", data: "data", sortOrder: "sortOrder" }, outputs: { rowClick: "rowClick", rowSelect: "rowSelect", sortOrderChange: "sortOrderChange", rowActive: "rowActive", columnSort: "columnSort", pageChange: "pageChange" }, ngImport: i0, template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n [tabindex]=\"(tableConfig$ | async)?.activateRowOnKeyboardNavigation ? 0 : -1\"\n #tableRef\n (focus)=\"listenToKeyboardEvents()\"\n (focusout)=\"unsubscribeFromKeyboardEvents(tableRef)\"\n (mouseenter)=\"listenToKeyboardEvents()\"\n (mouseleave)=\"unsubscribeFromKeyboardEvents(tableRef)\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortOrder$ | async | sortClass: column.key:'aria'\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n [attr.data-sort-order]=\"\n sortOrder$ | async | sortClass: column.key:'order'\n \"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading ||\n !column.value.sortable ||\n sortByKey(column.key, $event)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"\n sortOrder$ | async | sortClass: headerRow.key:'aria'\n \"\n ngClass=\"{{ headerRow.value.sortable ? 'sort ' : '' }} {{\n sortOrder$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading ||\n !headerRow.value.sortable ||\n sortByKey(headerRow.key, $event)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config.rows || {})[headerRow.key].transform,\n templateRef: (table.config.rows || {})[headerRow.key].templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n <tfoot *ngIf=\"(table$ | async)! as table\">\n <ng-container *ngIf=\"table.data.length > 0 && !(loading$ | async)\">\n <ng-container *ngIf=\"(calculations$ | async)! as calculations\">\n <tr\n *ngFor=\"let calculation of calculations.calculations; let i = index\"\n >\n <ng-container\n *ngIf=\"{\n showHeader: (colspan$ | async) !== (footerColspan$ | async)\n } as footerRow\"\n >\n <th\n *ngIf=\"footerRow.showHeader\"\n [colSpan]=\"\n ((colspan$ | async) || 0) - ((footerColspan$ | async) || 0)\n \"\n scope=\"row\"\n >\n <ng-container\n *ngIf=\"table.config?.footer?.headers?.[calculation] as showHeader\"\n >{{showHeader === true ? (calculation | capitalCase): table.config.footer?.headers?.[calculation]}}\n </ng-container>\n </th>\n <ng-container\n *ngFor=\"\n let column of table.config?.columns | keyvalue: columnOrder\n \"\n >\n <td\n *ngIf=\"\n !column.value?.hidden && calculations.calculated[column.key]\n \"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-header]=\"\n !footerRow.showHeader && table.config.footer?.headers?.[calculation]\n ? table.config.footer?.headers?.[calculation] === true ? (calculation | capitalCase) : table.config.footer?.headers?.[calculation]\n : null\n \"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n [class.gt-no-content]=\"\n !calculations.calculated[column.key][calculation]\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformFooter\n : rawFooter\n \"\n [ngTemplateOutletContext]=\"{\n value: calculations.calculated[column.key][calculation],\n row: calculations.calculated[column.key],\n column: calculation,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n transform: (table.config.columns || {})[column.key]\n .transform\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </ng-container>\n </tr>\n </ng-container>\n </ng-container>\n </tfoot>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![\n table.info.lazyLoaded ? 0 : (currentPaginationIndex$ | async) || 0\n ];\n trackBy: trackRowByFn;\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseenter)=\"\n table?.config?.activateRowOnHover && _activateRow(row, i, $event)\n \"\n (mouseleave)=\"\n table?.config?.activateRowOnHover &&\n _activateRow(null, null, $event)\n \"\n [ngClass]=\"[\n !!isRowSelectedFn\n ? (row\n | rowSelection\n : selection\n : isRowSelectedFn\n : customClasses.selectedRow)\n : '',\n (rowActive$ | async)?.index === i ? customClasses.activeRow : ''\n ]\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config.columns || {})[column.key].transform,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[\n table.info.lazyLoaded\n ? 0\n : (currentPaginationIndex$ | async) || 0\n ]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseenter)=\"\n table?.config?.activateRowOnHover && _activateRow(row, i, $event)\n \"\n (mouseleave)=\"\n table?.config?.activateRowOnHover &&\n _activateRow(null, null, $event)\n \"\n [ngClass]=\"[\n !!isRowSelectedFn\n ? (row\n | rowSelection\n : selection\n : isRowSelectedFn\n : customClasses.selectedRow)\n : '',\n (rowActive$ | async)?.index === i ? customClasses.activeRow : ''\n ]\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config.rows || {})[row.key].transform,\n templateRef: (table.config.rows || {})[row.key].templateRef,\n index: table.config.rows ? y : i,\n data: table.data[\n table.info.lazyLoaded\n ? 0\n : (currentPaginationIndex$ | async) || 0\n ]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template\n #highlighted\n let-row=\"row\"\n let-column=\"column\"\n let-search=\"search\"\n let-transform=\"transform\"\n>\n <div\n *ngIf=\"!transform\"\n [innerHTML]=\"row[column.key] | highlight: search\"\n ></div>\n <div\n *ngIf=\"transform\"\n [innerHTML]=\"\n row[column.key]\n | dynamicPipe: transform.pipe:transform?.args\n | highlight: search\n \"\n ></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template #transformFooter let-value=\"value\" let-transform=\"transform\">\n {{\n (value | dynamicPipe: transform.pipe:transform?.args) ||\n (tableConfig$ | async)?.footer?.emptyContent\n }}\n</ng-template>\n<ng-template #rawFooter let-value=\"value\">\n {{ value || (tableConfig$ | async)?.footer?.emptyContent }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n", dependencies: [{ kind: "pipe", type: CapitalCasePipe, name: "capitalCase" }, { kind: "pipe", type: KeyValuePipe, name: "keyvalue" }, { kind: "pipe", type: SortClassPipe, name: "sortClass" }, { kind: "pipe", type: DashCasePipe, name: "dashCase" }, { kind: "pipe", type: RowSelectionPipe, name: "rowSelection" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "pipe", type: SlicePipe, name: "slice" }, { kind: "pipe", type: DynamicPipe, name: "dynamicPipe" }, { kind: "pipe", type: HighlightPipe, name: "highlight" }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
527
853
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: CoreComponent, decorators: [{
|
|
528
854
|
type: Component,
|
|
529
855
|
args: [{ selector: 'angular-generic-table', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
|
|
@@ -531,6 +857,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
531
857
|
KeyValuePipe,
|
|
532
858
|
SortClassPipe,
|
|
533
859
|
DashCasePipe,
|
|
860
|
+
RowSelectionPipe,
|
|
534
861
|
AsyncPipe,
|
|
535
862
|
NgTemplateOutlet,
|
|
536
863
|
SlicePipe,
|
|
@@ -539,10 +866,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
539
866
|
NgClass,
|
|
540
867
|
NgIf,
|
|
541
868
|
NgForOf,
|
|
542
|
-
], template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortOrder$ | async | sortClass: column.key:'aria'\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n [attr.data-sort-order]=\"\n sortOrder$ | async | sortClass: column.key:'order'\n \"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading ||\n !column.value.sortable ||\n sortByKey(column.key, $event)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"\n sortOrder$ | async | sortClass: headerRow.key:'aria'\n \"\n ngClass=\"{{ headerRow.value.sortable ? 'sort ' : '' }} {{\n sortOrder$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading ||\n !headerRow.value.sortable ||\n sortByKey(headerRow.key, $event)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config.rows || {})[headerRow.key].transform,\n templateRef: (table.config.rows || {})[headerRow.key].templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n <tfoot *ngIf=\"(table$ | async)! as table\">\n <ng-container *ngIf=\"table.data.length > 0 && !(loading$ | async)\">\n <ng-container *ngIf=\"(calculations$ | async)! as calculations\">\n <tr\n *ngFor=\"let calculation of calculations.calculations; let i = index\"\n >\n <ng-container\n *ngIf=\"{\n showHeader: (colspan$ | async) !== (footerColspan$ | async)\n } as footerRow\"\n >\n <th\n *ngIf=\"footerRow.showHeader\"\n [colSpan]=\"\n ((colspan$ | async) || 0) - ((footerColspan$ | async) || 0)\n \"\n scope=\"row\"\n >\n <ng-container\n *ngIf=\"table.config?.footer?.headers?.[calculation] as showHeader\"\n >{{showHeader === true ? (calculation | capitalCase): table.config.footer?.headers?.[calculation]}}\n </ng-container>\n </th>\n <ng-container\n *ngFor=\"\n let column of table.config?.columns | keyvalue: columnOrder\n \"\n >\n <td\n *ngIf=\"\n !column.value?.hidden && calculations.calculated[column.key]\n \"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-header]=\"\n !footerRow.showHeader && table.config.footer?.headers?.[calculation]\n ? table.config.footer?.headers?.[calculation] === true ? (calculation | capitalCase) : table.config.footer?.headers?.[calculation]\n : null\n \"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n [class.gt-no-content]=\"\n !calculations.calculated[column.key][calculation]\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformFooter\n : rawFooter\n \"\n [ngTemplateOutletContext]=\"{\n value: calculations.calculated[column.key][calculation],\n row: calculations.calculated[column.key],\n column: calculation,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n transform: (table.config.columns || {})[column.key]\n .transform\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </ng-container>\n </tr>\n </ng-container>\n </ng-container>\n </tfoot>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![(currentPage$ | async) || 0];\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseover)=\"table?.config?.rowHover && _hoverRow(row, i, $event)\"\n (mouseout)=\"table?.config?.rowHover && _hoverRow(null, null, $event)\"\n [class.gt-hover]=\"(rowHover$ | async)?.index === i\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config.columns || {})[column.key].transform,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseover)=\"table?.config?.rowHover && _hoverRow(row, i, $event)\"\n (mouseout)=\"\n table?.config?.rowHover && _hoverRow(null, null, $event)\n \"\n [class.gt-hover]=\"(rowHover$ | async)?.index === i\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config.rows || {})[row.key].transform,\n templateRef: (table.config.rows || {})[row.key].templateRef,\n index: table.config.rows ? y : i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template\n #highlighted\n let-row=\"row\"\n let-column=\"column\"\n let-search=\"search\"\n let-transform=\"transform\"\n>\n <div\n *ngIf=\"!transform\"\n [innerHTML]=\"row[column.key] | highlight: search\"\n ></div>\n <div\n *ngIf=\"transform\"\n [innerHTML]=\"\n row[column.key]\n | dynamicPipe: transform.pipe:transform?.args\n | highlight: search\n \"\n ></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template #transformFooter let-value=\"value\" let-transform=\"transform\">\n {{\n (value | dynamicPipe: transform.pipe:transform?.args) ||\n (tableConfig$ | async)?.footer?.emptyContent\n }}\n</ng-template>\n<ng-template #rawFooter let-value=\"value\">\n {{ value || (tableConfig$ | async)?.footer?.emptyContent }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n" }]
|
|
543
|
-
}], propDecorators: {
|
|
869
|
+
], template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n [tabindex]=\"(tableConfig$ | async)?.activateRowOnKeyboardNavigation ? 0 : -1\"\n #tableRef\n (focus)=\"listenToKeyboardEvents()\"\n (focusout)=\"unsubscribeFromKeyboardEvents(tableRef)\"\n (mouseenter)=\"listenToKeyboardEvents()\"\n (mouseleave)=\"unsubscribeFromKeyboardEvents(tableRef)\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortOrder$ | async | sortClass: column.key:'aria'\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n [attr.data-sort-order]=\"\n sortOrder$ | async | sortClass: column.key:'order'\n \"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading ||\n !column.value.sortable ||\n sortByKey(column.key, $event)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"\n sortOrder$ | async | sortClass: headerRow.key:'aria'\n \"\n ngClass=\"{{ headerRow.value.sortable ? 'sort ' : '' }} {{\n sortOrder$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading ||\n !headerRow.value.sortable ||\n sortByKey(headerRow.key, $event)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config.rows || {})[headerRow.key].transform,\n templateRef: (table.config.rows || {})[headerRow.key].templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n <tfoot *ngIf=\"(table$ | async)! as table\">\n <ng-container *ngIf=\"table.data.length > 0 && !(loading$ | async)\">\n <ng-container *ngIf=\"(calculations$ | async)! as calculations\">\n <tr\n *ngFor=\"let calculation of calculations.calculations; let i = index\"\n >\n <ng-container\n *ngIf=\"{\n showHeader: (colspan$ | async) !== (footerColspan$ | async)\n } as footerRow\"\n >\n <th\n *ngIf=\"footerRow.showHeader\"\n [colSpan]=\"\n ((colspan$ | async) || 0) - ((footerColspan$ | async) || 0)\n \"\n scope=\"row\"\n >\n <ng-container\n *ngIf=\"table.config?.footer?.headers?.[calculation] as showHeader\"\n >{{showHeader === true ? (calculation | capitalCase): table.config.footer?.headers?.[calculation]}}\n </ng-container>\n </th>\n <ng-container\n *ngFor=\"\n let column of table.config?.columns | keyvalue: columnOrder\n \"\n >\n <td\n *ngIf=\"\n !column.value?.hidden && calculations.calculated[column.key]\n \"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-header]=\"\n !footerRow.showHeader && table.config.footer?.headers?.[calculation]\n ? table.config.footer?.headers?.[calculation] === true ? (calculation | capitalCase) : table.config.footer?.headers?.[calculation]\n : null\n \"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n [class.gt-no-content]=\"\n !calculations.calculated[column.key][calculation]\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformFooter\n : rawFooter\n \"\n [ngTemplateOutletContext]=\"{\n value: calculations.calculated[column.key][calculation],\n row: calculations.calculated[column.key],\n column: calculation,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n transform: (table.config.columns || {})[column.key]\n .transform\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </ng-container>\n </tr>\n </ng-container>\n </ng-container>\n </tfoot>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![\n table.info.lazyLoaded ? 0 : (currentPaginationIndex$ | async) || 0\n ];\n trackBy: trackRowByFn;\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseenter)=\"\n table?.config?.activateRowOnHover && _activateRow(row, i, $event)\n \"\n (mouseleave)=\"\n table?.config?.activateRowOnHover &&\n _activateRow(null, null, $event)\n \"\n [ngClass]=\"[\n !!isRowSelectedFn\n ? (row\n | rowSelection\n : selection\n : isRowSelectedFn\n : customClasses.selectedRow)\n : '',\n (rowActive$ | async)?.index === i ? customClasses.activeRow : ''\n ]\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [attr.data-label]=\"\n table.config.mobileLayout && column.value.mobileHeader\n ? column.value.mobileHeader !== true\n ? column.value.mobileHeader\n : (column.value.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config.columns || {})[column.key].transform,\n templateRef: (table.config.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[\n table.info.lazyLoaded\n ? 0\n : (currentPaginationIndex$ | async) || 0\n ]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n (click)=\"table?.config?.rowClick && _rowClick(row, i, $event)\"\n (mouseenter)=\"\n table?.config?.activateRowOnHover && _activateRow(row, i, $event)\n \"\n (mouseleave)=\"\n table?.config?.activateRowOnHover &&\n _activateRow(null, null, $event)\n \"\n [ngClass]=\"[\n !!isRowSelectedFn\n ? (row\n | rowSelection\n : selection\n : isRowSelectedFn\n : customClasses.selectedRow)\n : '',\n (rowActive$ | async)?.index === i ? customClasses.activeRow : ''\n ]\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config.rows || {})[row.key].transform,\n templateRef: (table.config.rows || {})[row.key].templateRef,\n index: table.config.rows ? y : i,\n data: table.data[\n table.info.lazyLoaded\n ? 0\n : (currentPaginationIndex$ | async) || 0\n ]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template\n #highlighted\n let-row=\"row\"\n let-column=\"column\"\n let-search=\"search\"\n let-transform=\"transform\"\n>\n <div\n *ngIf=\"!transform\"\n [innerHTML]=\"row[column.key] | highlight: search\"\n ></div>\n <div\n *ngIf=\"transform\"\n [innerHTML]=\"\n row[column.key]\n | dynamicPipe: transform.pipe:transform?.args\n | highlight: search\n \"\n ></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template #transformFooter let-value=\"value\" let-transform=\"transform\">\n {{\n (value | dynamicPipe: transform.pipe:transform?.args) ||\n (tableConfig$ | async)?.footer?.emptyContent\n }}\n</ng-template>\n<ng-template #rawFooter let-value=\"value\">\n {{ value || (tableConfig$ | async)?.footer?.emptyContent }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n" }]
|
|
870
|
+
}], propDecorators: { navigationKeys: [{
|
|
871
|
+
type: Input
|
|
872
|
+
}], selectKeys: [{
|
|
873
|
+
type: Input
|
|
874
|
+
}], loading: [{
|
|
875
|
+
type: Input
|
|
876
|
+
}], paginationIndex: [{
|
|
877
|
+
type: Input
|
|
878
|
+
}], pagingInfo: [{
|
|
544
879
|
type: Input
|
|
545
|
-
}],
|
|
880
|
+
}], customClasses: [{
|
|
881
|
+
type: Input
|
|
882
|
+
}], isRowSelectedFn: [{
|
|
883
|
+
type: Input
|
|
884
|
+
}], selection: [{
|
|
885
|
+
type: Input
|
|
886
|
+
}], rowIdKey: [{
|
|
887
|
+
type: Input
|
|
888
|
+
}], generateRowId: [{
|
|
889
|
+
type: Input
|
|
890
|
+
}], trackRowByFn: [{
|
|
546
891
|
type: Input
|
|
547
892
|
}], search: [{
|
|
548
893
|
type: Input
|
|
@@ -554,13 +899,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
554
899
|
type: Input
|
|
555
900
|
}], rowClick: [{
|
|
556
901
|
type: Output
|
|
902
|
+
}], rowSelect: [{
|
|
903
|
+
type: Output
|
|
557
904
|
}], sortOrderChange: [{
|
|
558
|
-
type: Output
|
|
559
|
-
|
|
560
|
-
}], rowHover: [{
|
|
905
|
+
type: Output
|
|
906
|
+
}], rowActive: [{
|
|
561
907
|
type: Output
|
|
562
908
|
}], columnSort: [{
|
|
563
909
|
type: Output
|
|
910
|
+
}], pageChange: [{
|
|
911
|
+
type: Output
|
|
564
912
|
}] } });
|
|
565
913
|
|
|
566
914
|
class GtDeltaComponent {
|
|
@@ -695,6 +1043,7 @@ GenericTableCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0",
|
|
|
695
1043
|
SortClassPipe,
|
|
696
1044
|
DashCasePipe,
|
|
697
1045
|
HighlightPipe,
|
|
1046
|
+
RowSelectionPipe,
|
|
698
1047
|
CapitalCasePipe,
|
|
699
1048
|
CapitalCasePipe,
|
|
700
1049
|
DynamicPipe,
|
|
@@ -711,18 +1060,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
711
1060
|
SortClassPipe,
|
|
712
1061
|
DashCasePipe,
|
|
713
1062
|
HighlightPipe,
|
|
1063
|
+
RowSelectionPipe,
|
|
714
1064
|
CapitalCasePipe,
|
|
715
1065
|
CapitalCasePipe,
|
|
716
1066
|
DynamicPipe,
|
|
717
1067
|
GtDeltaComponent,
|
|
718
1068
|
],
|
|
719
1069
|
exports: [CoreComponent, GtDeltaComponent],
|
|
1070
|
+
declarations: [],
|
|
720
1071
|
}]
|
|
721
1072
|
}] });
|
|
722
1073
|
|
|
723
1074
|
class PaginationComponent {
|
|
724
1075
|
constructor() {
|
|
725
|
-
this.
|
|
1076
|
+
this._table$ = new ReplaySubject(1);
|
|
726
1077
|
this._ariaLabels = {
|
|
727
1078
|
nav: 'Table pagination',
|
|
728
1079
|
button: 'Go to page ',
|
|
@@ -733,58 +1084,111 @@ class PaginationComponent {
|
|
|
733
1084
|
button: 'page-link',
|
|
734
1085
|
};
|
|
735
1086
|
this._paginationLength = 5;
|
|
736
|
-
|
|
1087
|
+
/** paginationListItems$ - observable for page numbers to show based on number of pages and current position */
|
|
1088
|
+
this.paginationListItems$ = this._table$.pipe(switchMap((core) => combineLatest([
|
|
1089
|
+
core === null || core === void 0 ? void 0 : core.table$.pipe(pluck('info')),
|
|
1090
|
+
core === null || core === void 0 ? void 0 : core.currentPaginationIndex$,
|
|
1091
|
+
])), map(([info, currentPage]) => this._generateList(info.pageTotal, currentPage)), shareReplay(1));
|
|
1092
|
+
}
|
|
1093
|
+
get pagingInfo() {
|
|
1094
|
+
return (this._pagingInfo || {
|
|
1095
|
+
pageNext: null,
|
|
1096
|
+
pageCurrent: null,
|
|
1097
|
+
pagePrevious: null,
|
|
1098
|
+
pageSize: null,
|
|
1099
|
+
numberOfRecords: null,
|
|
1100
|
+
pageTotal: null,
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
/** pagingInfo
|
|
1104
|
+
* @description when provided, pagination component will use this information to render pagination instead of data from table. Use this option when pagination is handled by backend (server side).
|
|
1105
|
+
* @type info - metadata for pagination component
|
|
1106
|
+
*/
|
|
1107
|
+
set pagingInfo(info) {
|
|
1108
|
+
this._pagingInfo = info;
|
|
737
1109
|
}
|
|
738
1110
|
get paginationLength() {
|
|
739
1111
|
return this._paginationLength;
|
|
740
1112
|
}
|
|
741
|
-
|
|
742
|
-
|
|
1113
|
+
/** paginationLength
|
|
1114
|
+
* @description number of buttons to show in pagination
|
|
1115
|
+
* @type length - number of buttons to show. Defaults to: `5`
|
|
1116
|
+
*/
|
|
1117
|
+
set paginationLength(length) {
|
|
1118
|
+
this._paginationLength = +length;
|
|
743
1119
|
}
|
|
744
1120
|
get classes() {
|
|
745
1121
|
return this._classes;
|
|
746
1122
|
}
|
|
747
|
-
|
|
748
|
-
|
|
1123
|
+
/** classes
|
|
1124
|
+
* @description classes that should be used within pagination component for different elements
|
|
1125
|
+
* @type classes - classes to be used. Defaults to: `{
|
|
1126
|
+
* ul: 'pagination',
|
|
1127
|
+
* li: 'page-item',
|
|
1128
|
+
* button: 'page-link',
|
|
1129
|
+
* }`
|
|
1130
|
+
*/
|
|
1131
|
+
set classes(classes) {
|
|
1132
|
+
this._classes = classes;
|
|
749
1133
|
}
|
|
750
1134
|
get ariaLabels() {
|
|
751
1135
|
return this._ariaLabels;
|
|
752
1136
|
}
|
|
753
|
-
|
|
754
|
-
|
|
1137
|
+
/** ariaLabels
|
|
1138
|
+
* @description aria labels that describe pagination component
|
|
1139
|
+
* @type labels - aria labels for pagination. Defaults to: `{
|
|
1140
|
+
* nav: 'Table pagination',
|
|
1141
|
+
* button: 'Go to page ',
|
|
1142
|
+
* }`
|
|
1143
|
+
*/
|
|
1144
|
+
set ariaLabels(labels) {
|
|
1145
|
+
this._ariaLabels = labels;
|
|
755
1146
|
}
|
|
756
1147
|
get table() {
|
|
757
1148
|
return this._table;
|
|
758
1149
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1150
|
+
/** table
|
|
1151
|
+
* @description table component to which pagination is attached
|
|
1152
|
+
* @type tableRef - table component
|
|
1153
|
+
*/
|
|
1154
|
+
set table(tableRef) {
|
|
1155
|
+
this._table = tableRef;
|
|
1156
|
+
this._table$.next(tableRef);
|
|
762
1157
|
}
|
|
763
|
-
|
|
1158
|
+
/** generate list - generate an array with page numbers to show based on number of pages and current position
|
|
1159
|
+
* @param numberOfPages number of pages to show
|
|
1160
|
+
* @param currentPosition current position (page index) being shown in table
|
|
1161
|
+
* @returns Array<number> array of page numbers to show
|
|
1162
|
+
*/
|
|
1163
|
+
_generateList(numberOfPages, currentPosition) {
|
|
764
1164
|
const middle = Math.floor(this.paginationLength / 2);
|
|
765
|
-
const length =
|
|
1165
|
+
const length = numberOfPages < this.paginationLength
|
|
1166
|
+
? numberOfPages
|
|
1167
|
+
: this.paginationLength;
|
|
766
1168
|
return Array.from({ length }, (_, i) => {
|
|
767
1169
|
if (i === 0) {
|
|
768
1170
|
return 1;
|
|
769
1171
|
}
|
|
770
|
-
else if (
|
|
1172
|
+
else if (numberOfPages < this.paginationLength) {
|
|
771
1173
|
return i + 1;
|
|
772
1174
|
}
|
|
773
1175
|
else if (i + 1 === length) {
|
|
774
|
-
return
|
|
1176
|
+
return numberOfPages;
|
|
775
1177
|
}
|
|
776
|
-
else if (currentPosition > middle &&
|
|
1178
|
+
else if (currentPosition > middle &&
|
|
1179
|
+
currentPosition < numberOfPages - middle) {
|
|
777
1180
|
return i + currentPosition - (middle - 1);
|
|
778
1181
|
}
|
|
779
1182
|
else if (currentPosition > middle &&
|
|
780
|
-
currentPosition <
|
|
1183
|
+
currentPosition < numberOfPages - (middle - 1)) {
|
|
781
1184
|
return i + currentPosition - middle;
|
|
782
1185
|
}
|
|
783
1186
|
else if (currentPosition > middle &&
|
|
784
|
-
currentPosition ===
|
|
1187
|
+
currentPosition === numberOfPages - (middle - 1)) {
|
|
785
1188
|
return i + currentPosition - (middle + 1);
|
|
786
1189
|
}
|
|
787
|
-
else if (currentPosition > middle &&
|
|
1190
|
+
else if (currentPosition > middle &&
|
|
1191
|
+
currentPosition === numberOfPages - 1) {
|
|
788
1192
|
return i + currentPosition - (middle + 2);
|
|
789
1193
|
}
|
|
790
1194
|
else {
|
|
@@ -792,18 +1196,23 @@ class PaginationComponent {
|
|
|
792
1196
|
}
|
|
793
1197
|
});
|
|
794
1198
|
}
|
|
795
|
-
|
|
1199
|
+
/** go to page
|
|
1200
|
+
* @param index - page index to go to
|
|
1201
|
+
*/
|
|
1202
|
+
goToPage(index) {
|
|
796
1203
|
if (this.table) {
|
|
797
|
-
this.table.
|
|
1204
|
+
this.table.paginationIndex = index - 1;
|
|
798
1205
|
}
|
|
799
1206
|
}
|
|
800
1207
|
}
|
|
801
1208
|
PaginationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: PaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
802
|
-
PaginationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: PaginationComponent, isStandalone: true, selector: "angular-generic-table-pagination", inputs: { paginationLength: "paginationLength", classes: "classes", ariaLabels: "ariaLabels", table: "table" }, ngImport: i0, template: "<ng-container\n *ngIf=\"{\n links:
|
|
1209
|
+
PaginationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.1", type: PaginationComponent, isStandalone: true, selector: "angular-generic-table-pagination", inputs: { pagingInfo: "pagingInfo", paginationLength: "paginationLength", classes: "classes", ariaLabels: "ariaLabels", table: "table" }, ngImport: i0, template: "<ng-container\n *ngIf=\"{\n links: paginationListItems$ | async,\n currentPosition: table?.currentPaginationIndex$ | async\n } as pagination\"\n>\n <nav\n *ngIf=\"pagination.links && pagination.links.length > 1\"\n role=\"navigation\"\n [attr.aria-label]=\"ariaLabels.nav\"\n class=\"gt-pagination\"\n [class]=\"classes.nav\"\n >\n <ul [class]=\"classes.ul\">\n <ng-container\n *ngFor=\"\n let position of pagination!.links;\n let i = index;\n let last = last\n \"\n >\n <li\n [class]=\"classes.li\"\n [class.active]=\"position === (pagination!.currentPosition || 0) + 1\"\n >\n <button\n [class]=\"classes.button\"\n [attr.aria-label]=\"ariaLabels.button + position\"\n (click)=\"goToPage(position)\"\n >\n {{ position }}\n </button>\n </li>\n <li\n [class]=\"classes.li\"\n class=\"gt-ellipsis\"\n *ngIf=\"position + 1 !== pagination!.links![i + 1] && !last\"\n >\n <button [class]=\"classes.button\" disabled tabindex=\"-1\"></button>\n </li>\n </ng-container>\n </ul>\n </nav>\n</ng-container>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
803
1210
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImport: i0, type: PaginationComponent, decorators: [{
|
|
804
1211
|
type: Component,
|
|
805
|
-
args: [{ selector: 'angular-generic-table-pagination', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [
|
|
806
|
-
}], propDecorators: {
|
|
1212
|
+
args: [{ selector: 'angular-generic-table-pagination', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [CommonModule], template: "<ng-container\n *ngIf=\"{\n links: paginationListItems$ | async,\n currentPosition: table?.currentPaginationIndex$ | async\n } as pagination\"\n>\n <nav\n *ngIf=\"pagination.links && pagination.links.length > 1\"\n role=\"navigation\"\n [attr.aria-label]=\"ariaLabels.nav\"\n class=\"gt-pagination\"\n [class]=\"classes.nav\"\n >\n <ul [class]=\"classes.ul\">\n <ng-container\n *ngFor=\"\n let position of pagination!.links;\n let i = index;\n let last = last\n \"\n >\n <li\n [class]=\"classes.li\"\n [class.active]=\"position === (pagination!.currentPosition || 0) + 1\"\n >\n <button\n [class]=\"classes.button\"\n [attr.aria-label]=\"ariaLabels.button + position\"\n (click)=\"goToPage(position)\"\n >\n {{ position }}\n </button>\n </li>\n <li\n [class]=\"classes.li\"\n class=\"gt-ellipsis\"\n *ngIf=\"position + 1 !== pagination!.links![i + 1] && !last\"\n >\n <button [class]=\"classes.button\" disabled tabindex=\"-1\"></button>\n </li>\n </ng-container>\n </ul>\n </nav>\n</ng-container>\n" }]
|
|
1213
|
+
}], propDecorators: { pagingInfo: [{
|
|
1214
|
+
type: Input
|
|
1215
|
+
}], paginationLength: [{
|
|
807
1216
|
type: Input
|
|
808
1217
|
}], classes: [{
|
|
809
1218
|
type: Input
|
|
@@ -834,5 +1243,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.1", ngImpor
|
|
|
834
1243
|
* Generated bundle index. Do not edit.
|
|
835
1244
|
*/
|
|
836
1245
|
|
|
837
|
-
export { CoreComponent, CoreService, GenericTableCoreModule, GenericTablePaginationModule, GtDeltaComponent, PaginationComponent };
|
|
1246
|
+
export { CapitalCasePipe, CoreComponent, CoreService, DashCasePipe, DynamicPipe, GenericTableCoreModule, GenericTablePaginationModule, GtDeltaComponent, HighlightPipe, PaginationComponent, SortClassPipe, calculate, capitalize, chunk, dashed, parseSortOrderParams, search, sortOnMultipleKeys, sortOrderConfigToParam, sortOrderToParams };
|
|
838
1247
|
//# sourceMappingURL=angular-generic-table-core.mjs.map
|