@skyux/code-examples 13.6.1 → 13.6.2
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.
|
@@ -7,7 +7,7 @@ import { SkyKeyInfoModule, SkyStatusIndicatorModule, SkyAlertModule, SkyIllustra
|
|
|
7
7
|
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
8
|
import * as i1$1 from '@angular/forms';
|
|
9
9
|
import { FormControl, FormBuilder, ReactiveFormsModule, FormsModule, Validators, FormGroup } from '@angular/forms';
|
|
10
|
-
import { switchMap, of, Subject, takeUntil, Subscription, delay as delay$1, tap, shareReplay, map as map$1 } from 'rxjs';
|
|
10
|
+
import { switchMap, of, Subject, takeUntil, Subscription, delay as delay$1, fromEvent, tap, shareReplay, map as map$1 } from 'rxjs';
|
|
11
11
|
import * as i3 from '@skyux/modals';
|
|
12
12
|
import { SkyModalInstance, SkyModalModule, SkyModalService, SkyConfirmService, SkyConfirmType } from '@skyux/modals';
|
|
13
13
|
import * as i1$2 from '@skyux/tabs';
|
|
@@ -5708,7 +5708,7 @@ class ViewGridComponent {
|
|
|
5708
5708
|
this.#dataManagerSvc.initDataView(this.#viewConfig);
|
|
5709
5709
|
this.#dataManagerSvc
|
|
5710
5710
|
.getDataStateUpdates(this.viewId)
|
|
5711
|
-
.pipe(takeUntil
|
|
5711
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
|
5712
5712
|
.subscribe((state) => {
|
|
5713
5713
|
this.#dataState = state;
|
|
5714
5714
|
this.#setInitialColumnOrder();
|
|
@@ -5717,7 +5717,7 @@ class ViewGridComponent {
|
|
|
5717
5717
|
});
|
|
5718
5718
|
this.#dataManagerSvc
|
|
5719
5719
|
.getActiveViewIdUpdates()
|
|
5720
|
-
.pipe(takeUntil
|
|
5720
|
+
.pipe(takeUntil(this.#ngUnsubscribe))
|
|
5721
5721
|
.subscribe((id) => {
|
|
5722
5722
|
this.isActive = id === this.viewId;
|
|
5723
5723
|
this.#changeDetector.markForCheck();
|
|
@@ -5757,6 +5757,18 @@ class ViewGridComponent {
|
|
|
5757
5757
|
#onGridReady(event) {
|
|
5758
5758
|
this.#gridApi = event.api;
|
|
5759
5759
|
this.#updateData();
|
|
5760
|
+
// When the grid is destroyed, unsubscribe from all grid events.
|
|
5761
|
+
const gridSubscription = new Subscription();
|
|
5762
|
+
gridSubscription.add(fromEvent(this.#gridApi, 'gridPreDestroyed').subscribe(() => {
|
|
5763
|
+
gridSubscription.unsubscribe();
|
|
5764
|
+
}));
|
|
5765
|
+
// Keep the data manager sort option in sync with grid sort changes.
|
|
5766
|
+
gridSubscription.add(fromEvent(this.#gridApi, 'sortChanged').subscribe((sortChanged) => {
|
|
5767
|
+
const sortOption = (this.#dataManagerSvc.getCurrentDataManagerConfig().sortOptions ?? []).find((option) => (sortChanged.columns ?? []).some((col) => col.getColId() === option.propertyName));
|
|
5768
|
+
const state = new SkyDataManagerState(this.#dataState);
|
|
5769
|
+
state.activeSortOption = sortOption;
|
|
5770
|
+
this.#dataManagerSvc.updateDataState(state, this.viewId);
|
|
5771
|
+
}));
|
|
5760
5772
|
}
|
|
5761
5773
|
#searchItems(items) {
|
|
5762
5774
|
let searchedItems = items;
|
|
@@ -5796,6 +5808,17 @@ class ViewGridComponent {
|
|
|
5796
5808
|
return col1Index - col2Index;
|
|
5797
5809
|
}
|
|
5798
5810
|
});
|
|
5811
|
+
// Update the grid's initial sort based on the data state's active sort option.
|
|
5812
|
+
const field = this.#dataState.activeSortOption?.propertyName;
|
|
5813
|
+
const descending = this.#dataState.activeSortOption?.descending ?? false;
|
|
5814
|
+
this.#columnDefs.forEach((column) => {
|
|
5815
|
+
column.initialSort =
|
|
5816
|
+
field && field === column.field
|
|
5817
|
+
? descending
|
|
5818
|
+
? 'desc'
|
|
5819
|
+
: 'asc'
|
|
5820
|
+
: undefined;
|
|
5821
|
+
});
|
|
5799
5822
|
this.isGridInitialized = true;
|
|
5800
5823
|
}
|
|
5801
5824
|
#updateData() {
|
|
@@ -5803,7 +5826,10 @@ class ViewGridComponent {
|
|
|
5803
5826
|
if (this.#dataState.onlyShowSelected) {
|
|
5804
5827
|
this.displayedItems = this.displayedItems.filter((item) => item.selected);
|
|
5805
5828
|
}
|
|
5806
|
-
if (this.
|
|
5829
|
+
if (!this.isActive) {
|
|
5830
|
+
// Do nothing if the grid is not the active view.
|
|
5831
|
+
}
|
|
5832
|
+
else if (this.displayedItems.length > 0) {
|
|
5807
5833
|
this.#gridApi?.hideOverlay();
|
|
5808
5834
|
}
|
|
5809
5835
|
else {
|
|
@@ -5901,6 +5927,19 @@ class ViewRepeaterComponent {
|
|
|
5901
5927
|
if (this.#dataState.onlyShowSelected) {
|
|
5902
5928
|
this.displayedItems = this.displayedItems.filter((item) => item.selected);
|
|
5903
5929
|
}
|
|
5930
|
+
const sortOption = this.#dataState.activeSortOption;
|
|
5931
|
+
if (sortOption?.propertyName) {
|
|
5932
|
+
const field = sortOption.propertyName;
|
|
5933
|
+
const descending = sortOption.descending ?? false;
|
|
5934
|
+
this.displayedItems.sort((a, b) => {
|
|
5935
|
+
const aValue = String(a[field]);
|
|
5936
|
+
const bValue = String(b[field]);
|
|
5937
|
+
if (descending) {
|
|
5938
|
+
return bValue.localeCompare(aValue);
|
|
5939
|
+
}
|
|
5940
|
+
return aValue.localeCompare(bValue);
|
|
5941
|
+
});
|
|
5942
|
+
}
|
|
5904
5943
|
this.#dataManagerSvc.updateDataSummary({
|
|
5905
5944
|
totalItems: this.items.length,
|
|
5906
5945
|
itemsMatching: this.displayedItems.length,
|