@den4ik92/ng2-smart-table 19.2.4 → 19.2.6
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 +30 -44
- package/fesm2022/den4ik92-ng2-smart-table.mjs.map +1 -1
- package/lib/lib/data-source/data-source.d.ts +2 -3
- package/lib/lib/data-source/local/local.data-source.d.ts +1 -1
- package/lib/lib/interfaces/smart-table.models.d.ts +1 -2
- package/package.json +1 -1
|
@@ -465,7 +465,6 @@ var SmartTableOnChangedEventName;
|
|
|
465
465
|
SmartTableOnChangedEventName["sort"] = "sort";
|
|
466
466
|
SmartTableOnChangedEventName["add"] = "add";
|
|
467
467
|
SmartTableOnChangedEventName["remove"] = "remove";
|
|
468
|
-
SmartTableOnChangedEventName["append"] = "append";
|
|
469
468
|
SmartTableOnChangedEventName["appendMany"] = "appendMany";
|
|
470
469
|
SmartTableOnChangedEventName["prepend"] = "prepend";
|
|
471
470
|
SmartTableOnChangedEventName["refresh"] = "refresh";
|
|
@@ -484,7 +483,7 @@ class DataSource {
|
|
|
484
483
|
display: false,
|
|
485
484
|
perPageSelect: [],
|
|
486
485
|
});
|
|
487
|
-
this.data = [];
|
|
486
|
+
this.data = signal([]);
|
|
488
487
|
}
|
|
489
488
|
refresh() {
|
|
490
489
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.refresh });
|
|
@@ -496,28 +495,23 @@ class DataSource {
|
|
|
496
495
|
return this.onChangedSource.asObservable();
|
|
497
496
|
}
|
|
498
497
|
prepend(element) {
|
|
499
|
-
this.data.
|
|
498
|
+
this.data.update((old) => [element, ...old]);
|
|
500
499
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.prepend, newItems: [element] });
|
|
501
500
|
return Promise.resolve(true);
|
|
502
501
|
}
|
|
503
502
|
appendMany(elements) {
|
|
504
|
-
this.data
|
|
505
|
-
this.emitOnChanged({ action: SmartTableOnChangedEventName.appendMany, newItems: elements }
|
|
506
|
-
return Promise.resolve(true);
|
|
507
|
-
}
|
|
508
|
-
append(element) {
|
|
509
|
-
this.data.push(element);
|
|
510
|
-
this.emitOnChanged({ action: SmartTableOnChangedEventName.append, newItems: [element] });
|
|
503
|
+
this.data.update((old) => [...old, ...elements,]);
|
|
504
|
+
this.emitOnChanged({ action: SmartTableOnChangedEventName.appendMany, newItems: elements });
|
|
511
505
|
return Promise.resolve(true);
|
|
512
506
|
}
|
|
513
507
|
add(element) {
|
|
514
|
-
this.data.
|
|
508
|
+
this.data.update((old) => [...old, element,]);
|
|
515
509
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.add, newItems: [element] });
|
|
516
510
|
return Promise.resolve(true);
|
|
517
511
|
}
|
|
518
512
|
remove(element) {
|
|
519
|
-
this.data
|
|
520
|
-
this.emitOnChanged({ action: SmartTableOnChangedEventName.remove, item: element }
|
|
513
|
+
this.data.update((old) => old.filter((el) => el !== element));
|
|
514
|
+
this.emitOnChanged({ action: SmartTableOnChangedEventName.remove, item: element });
|
|
521
515
|
return Promise.resolve(true);
|
|
522
516
|
}
|
|
523
517
|
update(oldItem, newItem) {
|
|
@@ -525,7 +519,7 @@ class DataSource {
|
|
|
525
519
|
return Promise.resolve(true);
|
|
526
520
|
}
|
|
527
521
|
empty() {
|
|
528
|
-
this.data
|
|
522
|
+
this.data.set([]);
|
|
529
523
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.empty });
|
|
530
524
|
return Promise.resolve(true);
|
|
531
525
|
}
|
|
@@ -579,24 +573,17 @@ class DataSource {
|
|
|
579
573
|
}
|
|
580
574
|
}
|
|
581
575
|
emitOnChanged(eventData, newElements) {
|
|
582
|
-
const actionData =
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
filters: this.getFilters(),
|
|
589
|
-
sort: this.getSort(),
|
|
590
|
-
};
|
|
591
|
-
if (eventData.action === SmartTableOnChangedEventName.remove) {
|
|
592
|
-
return {
|
|
593
|
-
...emitData,
|
|
594
|
-
elements: elements.filter((el) => el !== eventData.item),
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
return emitData;
|
|
576
|
+
const actionData = {
|
|
577
|
+
...eventData,
|
|
578
|
+
elements: newElements || this.data(),
|
|
579
|
+
paging: this.pagingConf(),
|
|
580
|
+
filters: this.getFilters(),
|
|
581
|
+
sort: this.getSort(),
|
|
598
582
|
};
|
|
599
|
-
|
|
583
|
+
if (eventData.action === SmartTableOnChangedEventName.remove) {
|
|
584
|
+
actionData.elements = (newElements || this.data()).filter((el) => el !== eventData.item);
|
|
585
|
+
}
|
|
586
|
+
this.onChangedSource.next(actionData);
|
|
600
587
|
}
|
|
601
588
|
}
|
|
602
589
|
|
|
@@ -647,10 +634,10 @@ class LocalDataSource extends DataSource {
|
|
|
647
634
|
super();
|
|
648
635
|
this.filteredAndSorted = signal([]);
|
|
649
636
|
this.count = computed(() => this.filteredAndSorted().length);
|
|
650
|
-
this.data
|
|
637
|
+
this.data.set(data);
|
|
651
638
|
}
|
|
652
639
|
load(data) {
|
|
653
|
-
this.data
|
|
640
|
+
this.data.set(data);
|
|
654
641
|
this.emitOnChanged({ action: SmartTableOnChangedEventName.load });
|
|
655
642
|
return Promise.resolve(true);
|
|
656
643
|
}
|
|
@@ -662,12 +649,12 @@ class LocalDataSource extends DataSource {
|
|
|
662
649
|
this.reset(true);
|
|
663
650
|
return super.appendMany(elements);
|
|
664
651
|
}
|
|
665
|
-
|
|
652
|
+
add(element) {
|
|
666
653
|
this.reset(true);
|
|
667
|
-
return super.
|
|
654
|
+
return super.add(element);
|
|
668
655
|
}
|
|
669
656
|
getAll() {
|
|
670
|
-
const data = this.data.slice(0);
|
|
657
|
+
const data = this.data().slice(0);
|
|
671
658
|
return Promise.resolve(data);
|
|
672
659
|
}
|
|
673
660
|
reset(silent = false) {
|
|
@@ -693,8 +680,8 @@ class LocalDataSource extends DataSource {
|
|
|
693
680
|
emitOnChanged(event) {
|
|
694
681
|
let renderData = this.filteredAndSorted();
|
|
695
682
|
const action = event.action;
|
|
696
|
-
if (['filter', 'refresh', 'load'].includes(action)) {
|
|
697
|
-
renderData = this.filter(this.data.slice(0));
|
|
683
|
+
if (['filter', 'refresh', 'load', 'add', 'prepend', 'appendMany'].includes(action)) {
|
|
684
|
+
renderData = this.filter(this.data().slice(0));
|
|
698
685
|
this.filteredAndSorted.set(this.sort(renderData));
|
|
699
686
|
renderData = this.filteredAndSorted();
|
|
700
687
|
}
|
|
@@ -747,7 +734,7 @@ class ServerDataSource extends DataSource {
|
|
|
747
734
|
this.requestFunction = requestFunction;
|
|
748
735
|
}
|
|
749
736
|
getAll() {
|
|
750
|
-
return Promise.resolve(this.data);
|
|
737
|
+
return Promise.resolve(this.data());
|
|
751
738
|
}
|
|
752
739
|
getSort() {
|
|
753
740
|
return this.sortConf;
|
|
@@ -771,7 +758,7 @@ class ServerDataSource extends DataSource {
|
|
|
771
758
|
})
|
|
772
759
|
.pipe(switchMap((params) => this.requestFunction(params)))
|
|
773
760
|
.subscribe((res) => {
|
|
774
|
-
this.data
|
|
761
|
+
this.data.set(res.data);
|
|
775
762
|
this.pagingConf.update((old) => ({ ...old, total: res.total }));
|
|
776
763
|
super.emitOnChanged(eventData, res.data);
|
|
777
764
|
});
|
|
@@ -1606,15 +1593,14 @@ class Grid {
|
|
|
1606
1593
|
if (event.action === 'load') {
|
|
1607
1594
|
this.dataSet.deselectAll();
|
|
1608
1595
|
}
|
|
1609
|
-
if (event.action
|
|
1610
|
-
this.dataSet.setData(event.elements);
|
|
1611
|
-
}
|
|
1612
|
-
else {
|
|
1596
|
+
if (event.action === 'update') {
|
|
1613
1597
|
const changedRow = this.dataSet.findRowByData(event.oldItem);
|
|
1614
1598
|
if (changedRow) {
|
|
1615
1599
|
changedRow.setData(event.newItem || event.oldItem);
|
|
1616
1600
|
}
|
|
1601
|
+
return;
|
|
1617
1602
|
}
|
|
1603
|
+
this.dataSet.setData(event.elements);
|
|
1618
1604
|
}
|
|
1619
1605
|
prepareSource(source, initialSort, initialPaging) {
|
|
1620
1606
|
const preparedSource = source || new LocalDataSource();
|