@den4ik92/ng2-smart-table 19.2.6 → 19.2.8
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 +38 -27
- package/fesm2022/den4ik92-ng2-smart-table.mjs.map +1 -1
- package/lib/lib/data-source/data-source.d.ts +1 -1
- 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/lib/lib/helpers.d.ts +1 -0
- package/package.json +1 -1
|
@@ -175,6 +175,13 @@ function getLocalStorage(key) {
|
|
|
175
175
|
return null;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
+
function promiseDelay(time) {
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
setTimeout(() => {
|
|
181
|
+
resolve();
|
|
182
|
+
}, time);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
178
185
|
|
|
179
186
|
class TableColumnsEditorComponent {
|
|
180
187
|
constructor() {
|
|
@@ -494,31 +501,31 @@ class DataSource {
|
|
|
494
501
|
onChanged() {
|
|
495
502
|
return this.onChangedSource.asObservable();
|
|
496
503
|
}
|
|
497
|
-
prepend(element) {
|
|
504
|
+
async prepend(element) {
|
|
498
505
|
this.data.update((old) => [element, ...old]);
|
|
499
506
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.prepend, newItems: [element] });
|
|
500
507
|
return Promise.resolve(true);
|
|
501
508
|
}
|
|
502
|
-
appendMany(elements) {
|
|
509
|
+
async appendMany(elements) {
|
|
503
510
|
this.data.update((old) => [...old, ...elements,]);
|
|
504
511
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.appendMany, newItems: elements });
|
|
505
512
|
return Promise.resolve(true);
|
|
506
513
|
}
|
|
507
|
-
add(element) {
|
|
514
|
+
async add(element) {
|
|
508
515
|
this.data.update((old) => [...old, element,]);
|
|
509
516
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.add, newItems: [element] });
|
|
510
517
|
return Promise.resolve(true);
|
|
511
518
|
}
|
|
512
|
-
remove(element) {
|
|
519
|
+
async remove(element) {
|
|
513
520
|
this.data.update((old) => old.filter((el) => el !== element));
|
|
514
521
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.remove, item: element });
|
|
515
522
|
return Promise.resolve(true);
|
|
516
523
|
}
|
|
517
|
-
update(oldItem, newItem) {
|
|
524
|
+
async update(oldItem, newItem) {
|
|
518
525
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.update, oldItem, newItem });
|
|
519
526
|
return Promise.resolve(true);
|
|
520
527
|
}
|
|
521
|
-
empty() {
|
|
528
|
+
async empty() {
|
|
522
529
|
this.data.set([]);
|
|
523
530
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.empty });
|
|
524
531
|
return Promise.resolve(true);
|
|
@@ -530,7 +537,7 @@ class DataSource {
|
|
|
530
537
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.sort });
|
|
531
538
|
}
|
|
532
539
|
}
|
|
533
|
-
addFilter(newFilter, doEmit = true) {
|
|
540
|
+
async addFilter(newFilter, doEmit = true) {
|
|
534
541
|
if (!newFilter.field) {
|
|
535
542
|
return;
|
|
536
543
|
}
|
|
@@ -590,7 +597,7 @@ class DataSource {
|
|
|
590
597
|
function filterValues(value, search) {
|
|
591
598
|
return value.toString().toLowerCase().includes(search.toString().toLowerCase());
|
|
592
599
|
}
|
|
593
|
-
function isElementSatisfied(element, filters) {
|
|
600
|
+
async function isElementSatisfied(element, filters) {
|
|
594
601
|
return filters.every((filter) => {
|
|
595
602
|
if (!filter.search?.length) {
|
|
596
603
|
return true;
|
|
@@ -620,7 +627,7 @@ function compareValues(direction, a, b) {
|
|
|
620
627
|
return 0;
|
|
621
628
|
}
|
|
622
629
|
class LocalSorter {
|
|
623
|
-
static sort(data, field, direction, customCompare) {
|
|
630
|
+
static async sort(data, field, direction, customCompare) {
|
|
624
631
|
const dir = direction === "asc" ? 1 : -1;
|
|
625
632
|
const compare = customCompare ? customCompare : compareValues;
|
|
626
633
|
return data.sort((a, b) => {
|
|
@@ -636,9 +643,9 @@ class LocalDataSource extends DataSource {
|
|
|
636
643
|
this.count = computed(() => this.filteredAndSorted().length);
|
|
637
644
|
this.data.set(data);
|
|
638
645
|
}
|
|
639
|
-
load(data) {
|
|
646
|
+
async load(data) {
|
|
640
647
|
this.data.set(data);
|
|
641
|
-
this.emitOnChanged({ action: SmartTableOnChangedEventName.load });
|
|
648
|
+
this.emitOnChanged({ action: SmartTableOnChangedEventName.load }, data);
|
|
642
649
|
return Promise.resolve(true);
|
|
643
650
|
}
|
|
644
651
|
prepend(element) {
|
|
@@ -677,17 +684,17 @@ class LocalDataSource extends DataSource {
|
|
|
677
684
|
getFilters() {
|
|
678
685
|
return this.filters;
|
|
679
686
|
}
|
|
680
|
-
emitOnChanged(event) {
|
|
681
|
-
let renderData = this.filteredAndSorted();
|
|
687
|
+
async emitOnChanged(event, newElements) {
|
|
688
|
+
let renderData = this.filteredAndSorted().slice(0);
|
|
682
689
|
const action = event.action;
|
|
683
690
|
if (['filter', 'refresh', 'load', 'add', 'prepend', 'appendMany'].includes(action)) {
|
|
684
|
-
renderData = this.filter(this.data().slice(0));
|
|
685
|
-
this.
|
|
686
|
-
|
|
691
|
+
renderData = await this.filter(newElements || this.data().slice(0));
|
|
692
|
+
renderData = await this.sort(renderData);
|
|
693
|
+
this.filteredAndSorted.set(renderData);
|
|
687
694
|
}
|
|
688
|
-
if (
|
|
689
|
-
|
|
690
|
-
|
|
695
|
+
if (action === SmartTableOnChangedEventName.sort) {
|
|
696
|
+
renderData = await this.sort(renderData);
|
|
697
|
+
this.filteredAndSorted.set(renderData);
|
|
691
698
|
}
|
|
692
699
|
if (this.pagingConf().display &&
|
|
693
700
|
['page', 'paging', 'refresh', 'load', 'sort', 'filter'].includes(action)) {
|
|
@@ -698,19 +705,23 @@ class LocalDataSource extends DataSource {
|
|
|
698
705
|
this.setPage(this.pagingConf().page - 1);
|
|
699
706
|
}
|
|
700
707
|
}
|
|
701
|
-
sort(data) {
|
|
708
|
+
async sort(data) {
|
|
702
709
|
if (this.sortConf) {
|
|
703
|
-
|
|
710
|
+
return LocalSorter.sort(data, this.sortConf.field, this.sortConf.direction, this.sortConf.compare);
|
|
704
711
|
}
|
|
705
712
|
return data;
|
|
706
713
|
}
|
|
707
|
-
filter(data) {
|
|
708
|
-
if (this.filters.length
|
|
709
|
-
return data
|
|
710
|
-
return isElementSatisfied(item, this.filters);
|
|
711
|
-
});
|
|
714
|
+
async filter(data) {
|
|
715
|
+
if (!this.filters.length) {
|
|
716
|
+
return data;
|
|
712
717
|
}
|
|
713
|
-
|
|
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;
|
|
714
725
|
}
|
|
715
726
|
paginate(data) {
|
|
716
727
|
if (this.pagingConf().display) {
|