@servicemind.tis/tis-smart-table-viewer 2.3.6 → 2.3.7

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.
@@ -89,14 +89,12 @@ class ApiDataSource {
89
89
  this.loadingSubject.next(true);
90
90
  this.apiSubs = this.apiService.getList(url, (pageIndex + 1), pageSize, search, { filter }, { sortFilter }).pipe(catchError(() => of([])), finalize(() => this.loadingSubject.next(false))).subscribe(r => {
91
91
  console.log(`DataSource: Url: ${url}, Reply:`, r);
92
- if (r?.data?.length > 0) {
93
- this.totalDataLength.next(r?.total);
94
- }
95
- else {
96
- this.totalDataLength.next(0);
97
- }
98
- this.apiSubject.next(r?.data);
99
- this.extraDataSubject.next(r?.extraData);
92
+ // ✅ FIX: Ensure we always emit an array (even if empty) to prevent undefined issues
93
+ const data = r?.data || [];
94
+ const total = (Array.isArray(data) && data.length > 0) ? (r?.total || data.length) : 0;
95
+ this.totalDataLength.next(total);
96
+ this.apiSubject.next(data);
97
+ this.extraDataSubject.next(r?.extraData || null);
100
98
  });
101
99
  }
102
100
  loadWithCancellation(url, pageIndex, pageSize, search, filter, sortFilter, cancelSubject) {
@@ -111,14 +109,12 @@ class ApiDataSource {
111
109
  }
112
110
  this.apiSubs = apiCall$.subscribe(r => {
113
111
  console.log(`DataSource: Url: ${url}, Reply:`, r);
114
- if (r?.data?.length > 0) {
115
- this.totalDataLength.next(r?.total);
116
- }
117
- else {
118
- this.totalDataLength.next(0);
119
- }
120
- this.apiSubject.next(r?.data);
121
- this.extraDataSubject.next(r?.extraData);
112
+ // ✅ FIX: Ensure we always emit an array (even if empty) to prevent undefined issues
113
+ const data = r?.data || [];
114
+ const total = (Array.isArray(data) && data.length > 0) ? (r?.total || data.length) : 0;
115
+ this.totalDataLength.next(total);
116
+ this.apiSubject.next(data);
117
+ this.extraDataSubject.next(r?.extraData || null);
122
118
  });
123
119
  }
124
120
  }
@@ -2115,11 +2111,14 @@ class TisSmartTableViewerComponent {
2115
2111
  this._paginator.pageIndex = this.pageIndex;
2116
2112
  this._paginator.pageSize = this.pageSize;
2117
2113
  }
2114
+ // ✅ FIX: Always clear caches when new data arrives (even if empty)
2118
2115
  // Clear background cache when new data arrives
2119
2116
  this.clearRowBackgroundCache();
2120
2117
  // Pre-compute all row backgrounds for optimal performance
2121
2118
  this.computeAllRowBackgrounds();
2119
+ // ✅ FIX: Ensure selection state is updated even when data changes from empty to populated
2122
2120
  this.checkAllRowsSelected();
2121
+ // ✅ FIX: Force change detection by emitting events
2123
2122
  this.onDataLoaded.emit(true);
2124
2123
  this.onSetExtraData.emit(this.dataSource.extraDataSubject.value);
2125
2124
  // if (this.selectedRowIds && this.selectedRowIds.length) {
@@ -2142,8 +2141,12 @@ class TisSmartTableViewerComponent {
2142
2141
  if (this.filterFormGroupSubscription) {
2143
2142
  this.filterFormGroupSubscription.unsubscribe();
2144
2143
  }
2144
+ // ✅ FIX: Use custom comparator for distinctUntilChanged to properly detect form value changes
2145
2145
  this.filterFormGroupSubscription = this.filterFormGroup.valueChanges
2146
- .pipe(takeUntil(this._onDestroy), distinctUntilChanged()).subscribe(val => {
2146
+ .pipe(takeUntil(this._onDestroy), distinctUntilChanged((prev, curr) => {
2147
+ // Custom comparator: deep compare form values
2148
+ return JSON.stringify(prev) === JSON.stringify(curr);
2149
+ })).subscribe(val => {
2147
2150
  this.filterHasNonEmptyValue = ValidationHelper.hasNonEmptyValue(val);
2148
2151
  });
2149
2152
  }
@@ -2289,11 +2292,21 @@ class TisSmartTableViewerComponent {
2289
2292
  }
2290
2293
  // Compute all row backgrounds when data changes (runs once per data load)
2291
2294
  computeAllRowBackgrounds() {
2292
- if (!this.dataSource?.apiSubject.value || !this.rowsConfig.backgroundApplyFunction) {
2295
+ // FIX: Always clear the cache first to ensure fresh computation
2296
+ this.computedRowBackgrounds.clear();
2297
+ // ✅ FIX: Safely check if we have data and a background function
2298
+ if (!this.dataSource?.apiSubject?.value ||
2299
+ !Array.isArray(this.dataSource.apiSubject.value) ||
2300
+ !this.rowsConfig.backgroundApplyFunction) {
2301
+ return;
2302
+ }
2303
+ // ✅ FIX: Only compute backgrounds if we have actual data
2304
+ if (this.dataSource.apiSubject.value.length === 0) {
2293
2305
  return;
2294
2306
  }
2295
- this.computedRowBackgrounds.clear();
2296
2307
  this.dataSource.apiSubject.value.forEach((row) => {
2308
+ if (!row)
2309
+ return; // Skip null/undefined rows
2297
2310
  const rowId = row?.id || row?.[this.selectedRowKey] || JSON.stringify(row);
2298
2311
  try {
2299
2312
  const background = this.rowsConfig.backgroundApplyFunction(row);
@@ -2382,6 +2395,8 @@ class TisSmartTableViewerComponent {
2382
2395
  this.isAllExpanded = false;
2383
2396
  // Clear expansion state when loading new data to avoid stale expansion state
2384
2397
  CollectionHelper.clearSet(this.expandedRowIds);
2398
+ // ✅ FIX: Clear row background cache before loading new data to prevent stale computed backgrounds
2399
+ this.clearRowBackgroundCache();
2385
2400
  const filterFormData = this.filterFormGroup?.value;
2386
2401
  this.filterHasNonEmptyValue = ValidationHelper.hasFormData(filterFormData);
2387
2402
  // Build query string using helper