@sd-angular/core 19.0.30 → 19.0.31

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.
@@ -0,0 +1,3 @@
1
+ import type { SdTableColumn } from '../../models/table-column.model';
2
+ /** Internal local-sort comparison; intentionally not exported from the table entry point. */
3
+ export declare const compareLocalValues: (a: unknown, b: unknown, type: SdTableColumn["type"], direction: "ASC" | "DESC") => number;
@@ -3049,6 +3049,32 @@ const buildColumnWidthMap = (column) => {
3049
3049
  return result;
3050
3050
  };
3051
3051
 
3052
+ const sortValue = (value, type) => {
3053
+ if (value === null || value === undefined || value === '')
3054
+ return null;
3055
+ if (type === 'number') {
3056
+ const number = typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean' ? Number(value) : NaN;
3057
+ return Number.isNaN(number) ? null : number;
3058
+ }
3059
+ if (type === 'date' || type === 'datetime' || type === 'time') {
3060
+ const time = value instanceof Date ? value.getTime() : typeof value === 'string' || typeof value === 'number' ? new Date(value).getTime() : NaN;
3061
+ return Number.isNaN(time) ? null : time;
3062
+ }
3063
+ return String(value);
3064
+ };
3065
+ /** Internal local-sort comparison; intentionally not exported from the table entry point. */
3066
+ const compareLocalValues = (a, b, type, direction) => {
3067
+ const first = sortValue(a, type);
3068
+ const second = sortValue(b, type);
3069
+ // why: xếp rỗng trước khi xét chiều để DESC vẫn giữ rỗng ở cuối và không đảo các dòng bằng nhau.
3070
+ if (first === null)
3071
+ return second === null ? 0 : 1;
3072
+ if (second === null)
3073
+ return -1;
3074
+ const order = first < second ? -1 : first > second ? 1 : 0;
3075
+ return direction === 'DESC' ? -order : order;
3076
+ };
3077
+
3052
3078
  /* eslint-disable @typescript-eslint/no-explicit-any */
3053
3079
  const isTableItem = (item) => !!item && typeof item === 'object' && 'data' in item && 'meta' in item;
3054
3080
  const resolveItemData = (item) => (isTableItem(item) ? item.data : item);
@@ -3166,27 +3192,8 @@ const filterLocalItems = (localItems, option, filterInfo) => {
3166
3192
  items.sort((tableItemCurrent, tableItemNext) => {
3167
3193
  const dataVal = Utilities.getNestedValue(resolveItemData(tableItemCurrent), field);
3168
3194
  const nextVal = Utilities.getNestedValue(resolveItemData(tableItemNext), field);
3169
- if (type === 'number') {
3170
- return (dataVal || 0) - (nextVal || 0);
3171
- }
3172
- if (type === 'date' || type === 'datetime' || type === 'time') {
3173
- const d1 = new Date(dataVal || '').getTime();
3174
- const d2 = new Date(nextVal || '').getTime();
3175
- return d1 - d2;
3176
- }
3177
- const s1 = (dataVal || '').toString();
3178
- const s2 = (nextVal || '').toString();
3179
- if (s1 > s2) {
3180
- return 1;
3181
- }
3182
- if (s1 < s2) {
3183
- return -1;
3184
- }
3185
- return 0;
3195
+ return compareLocalValues(dataVal, nextVal, type, orderDirection);
3186
3196
  });
3187
- if (orderDirection === 'DESC') {
3188
- items.reverse();
3189
- }
3190
3197
  }
3191
3198
  }
3192
3199
  return {