@den4ik92/ng2-smart-table 19.2.7 → 19.2.9
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/fesm2022/den4ik92-ng2-smart-table.mjs +34 -27
- package/fesm2022/den4ik92-ng2-smart-table.mjs.map +1 -1
- package/lib/lib/data-set/data-set.d.ts +1 -0
- package/lib/lib/data-source/local/local.data-source.d.ts +3 -3
- package/lib/lib/data-source/local/local.filter.d.ts +1 -1
- package/lib/lib/data-source/local/local.sorter.d.ts +1 -1
- package/package.json +1 -1
|
@@ -503,25 +503,21 @@ class DataSource {
|
|
|
503
503
|
}
|
|
504
504
|
async prepend(element) {
|
|
505
505
|
this.data.update((old) => [element, ...old]);
|
|
506
|
-
await promiseDelay(50);
|
|
507
506
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.prepend, newItems: [element] });
|
|
508
507
|
return Promise.resolve(true);
|
|
509
508
|
}
|
|
510
509
|
async appendMany(elements) {
|
|
511
510
|
this.data.update((old) => [...old, ...elements,]);
|
|
512
|
-
await promiseDelay(50);
|
|
513
511
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.appendMany, newItems: elements });
|
|
514
512
|
return Promise.resolve(true);
|
|
515
513
|
}
|
|
516
514
|
async add(element) {
|
|
517
515
|
this.data.update((old) => [...old, element,]);
|
|
518
|
-
await promiseDelay(50);
|
|
519
516
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.add, newItems: [element] });
|
|
520
517
|
return Promise.resolve(true);
|
|
521
518
|
}
|
|
522
519
|
async remove(element) {
|
|
523
520
|
this.data.update((old) => old.filter((el) => el !== element));
|
|
524
|
-
await promiseDelay(50);
|
|
525
521
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.remove, item: element });
|
|
526
522
|
return Promise.resolve(true);
|
|
527
523
|
}
|
|
@@ -531,7 +527,6 @@ class DataSource {
|
|
|
531
527
|
}
|
|
532
528
|
async empty() {
|
|
533
529
|
this.data.set([]);
|
|
534
|
-
await promiseDelay(50);
|
|
535
530
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.empty });
|
|
536
531
|
return Promise.resolve(true);
|
|
537
532
|
}
|
|
@@ -562,7 +557,6 @@ class DataSource {
|
|
|
562
557
|
}
|
|
563
558
|
this.pagingConf.update((old) => ({ ...old, page: 1 }));
|
|
564
559
|
if (doEmit) {
|
|
565
|
-
await promiseDelay(50);
|
|
566
560
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.filter });
|
|
567
561
|
}
|
|
568
562
|
}
|
|
@@ -603,7 +597,7 @@ class DataSource {
|
|
|
603
597
|
function filterValues(value, search) {
|
|
604
598
|
return value.toString().toLowerCase().includes(search.toString().toLowerCase());
|
|
605
599
|
}
|
|
606
|
-
function isElementSatisfied(element, filters) {
|
|
600
|
+
async function isElementSatisfied(element, filters) {
|
|
607
601
|
return filters.every((filter) => {
|
|
608
602
|
if (!filter.search?.length) {
|
|
609
603
|
return true;
|
|
@@ -633,7 +627,7 @@ function compareValues(direction, a, b) {
|
|
|
633
627
|
return 0;
|
|
634
628
|
}
|
|
635
629
|
class LocalSorter {
|
|
636
|
-
static sort(data, field, direction, customCompare) {
|
|
630
|
+
static async sort(data, field, direction, customCompare) {
|
|
637
631
|
const dir = direction === "asc" ? 1 : -1;
|
|
638
632
|
const compare = customCompare ? customCompare : compareValues;
|
|
639
633
|
return data.sort((a, b) => {
|
|
@@ -651,8 +645,7 @@ class LocalDataSource extends DataSource {
|
|
|
651
645
|
}
|
|
652
646
|
async load(data) {
|
|
653
647
|
this.data.set(data);
|
|
654
|
-
|
|
655
|
-
this.emitOnChanged({ action: SmartTableOnChangedEventName.load, }, data);
|
|
648
|
+
this.emitOnChanged({ action: SmartTableOnChangedEventName.load }, data);
|
|
656
649
|
return Promise.resolve(true);
|
|
657
650
|
}
|
|
658
651
|
prepend(element) {
|
|
@@ -691,17 +684,17 @@ class LocalDataSource extends DataSource {
|
|
|
691
684
|
getFilters() {
|
|
692
685
|
return this.filters;
|
|
693
686
|
}
|
|
694
|
-
emitOnChanged(event, newElements) {
|
|
695
|
-
let renderData = this.filteredAndSorted();
|
|
687
|
+
async emitOnChanged(event, newElements) {
|
|
688
|
+
let renderData = this.filteredAndSorted().slice(0);
|
|
696
689
|
const action = event.action;
|
|
697
690
|
if (['filter', 'refresh', 'load', 'add', 'prepend', 'appendMany'].includes(action)) {
|
|
698
|
-
renderData = this.filter(newElements || this.data().slice(0));
|
|
699
|
-
this.
|
|
700
|
-
|
|
691
|
+
renderData = await this.filter(newElements || this.data().slice(0));
|
|
692
|
+
renderData = await this.sort(renderData);
|
|
693
|
+
this.filteredAndSorted.set(renderData);
|
|
701
694
|
}
|
|
702
|
-
if (
|
|
703
|
-
|
|
704
|
-
|
|
695
|
+
if (action === SmartTableOnChangedEventName.sort) {
|
|
696
|
+
renderData = await this.sort(renderData);
|
|
697
|
+
this.filteredAndSorted.set(renderData);
|
|
705
698
|
}
|
|
706
699
|
if (this.pagingConf().display &&
|
|
707
700
|
['page', 'paging', 'refresh', 'load', 'sort', 'filter'].includes(action)) {
|
|
@@ -712,19 +705,23 @@ class LocalDataSource extends DataSource {
|
|
|
712
705
|
this.setPage(this.pagingConf().page - 1);
|
|
713
706
|
}
|
|
714
707
|
}
|
|
715
|
-
sort(data) {
|
|
708
|
+
async sort(data) {
|
|
716
709
|
if (this.sortConf) {
|
|
717
|
-
|
|
710
|
+
return LocalSorter.sort(data, this.sortConf.field, this.sortConf.direction, this.sortConf.compare);
|
|
718
711
|
}
|
|
719
712
|
return data;
|
|
720
713
|
}
|
|
721
|
-
filter(data) {
|
|
722
|
-
if (this.filters.length
|
|
723
|
-
return data
|
|
724
|
-
return isElementSatisfied(item, this.filters);
|
|
725
|
-
});
|
|
714
|
+
async filter(data) {
|
|
715
|
+
if (!this.filters.length) {
|
|
716
|
+
return data;
|
|
726
717
|
}
|
|
727
|
-
|
|
718
|
+
const filtered = [];
|
|
719
|
+
await Promise.all(data.map(async (element) => {
|
|
720
|
+
if (await isElementSatisfied(element, this.filters)) {
|
|
721
|
+
filtered.push(element);
|
|
722
|
+
}
|
|
723
|
+
}));
|
|
724
|
+
return filtered;
|
|
728
725
|
}
|
|
729
726
|
paginate(data) {
|
|
730
727
|
if (this.pagingConf().display) {
|
|
@@ -1394,6 +1391,11 @@ class DataSet {
|
|
|
1394
1391
|
this.data.set(data);
|
|
1395
1392
|
this.createRows();
|
|
1396
1393
|
}
|
|
1394
|
+
setColumnsConfig(columnSettings) {
|
|
1395
|
+
this.columnSettings = columnSettings;
|
|
1396
|
+
this.createColumns(columnSettings);
|
|
1397
|
+
this.createRows();
|
|
1398
|
+
}
|
|
1397
1399
|
getFirstRow() {
|
|
1398
1400
|
return this.rows()[0];
|
|
1399
1401
|
}
|
|
@@ -1657,7 +1659,12 @@ class Grid {
|
|
|
1657
1659
|
}
|
|
1658
1660
|
updateSettingsAndDataSet(settings, emittedEvent = 'refresh') {
|
|
1659
1661
|
this.settings.set(settings);
|
|
1660
|
-
this.dataSet
|
|
1662
|
+
if (this.dataSet) {
|
|
1663
|
+
this.dataSet.setColumnsConfig(settings.columns);
|
|
1664
|
+
}
|
|
1665
|
+
else {
|
|
1666
|
+
this.dataSet = new DataSet([], settings.columns);
|
|
1667
|
+
}
|
|
1661
1668
|
if (this.source) {
|
|
1662
1669
|
this.source.pagingConf.update((old) => ({
|
|
1663
1670
|
...old,
|