b2b-tools 0.1.1 → 0.1.3
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/README.md +1 -2
- package/fesm2022/b2b-tools.mjs +1091 -0
- package/fesm2022/b2b-tools.mjs.map +1 -0
- package/package.json +24 -13
- package/types/b2b-tools.d.ts +578 -0
- package/LICENCE +0 -21
- package/ng-package.json +0 -7
- package/src/lib/b2b-tools.spec.ts +0 -23
- package/src/lib/b2b-tools.ts +0 -15
- package/src/lib/components/advanced-card/advanced-card.css +0 -265
- package/src/lib/components/advanced-card/advanced-card.html +0 -117
- package/src/lib/components/advanced-card/advanced-card.ts +0 -75
- package/src/lib/components/advanced-card/index.ts +0 -2
- package/src/lib/components/advanced-card/types/card.types.ts +0 -37
- package/src/lib/components/advanced-card/types/index.ts +0 -1
- package/src/lib/components/advanced-table/advanced-table.component.css +0 -81
- package/src/lib/components/advanced-table/advanced-table.component.html +0 -56
- package/src/lib/components/advanced-table/advanced-table.component.ts +0 -469
- package/src/lib/components/advanced-table/index.ts +0 -2
- package/src/lib/components/advanced-table/parts/table-grid/table-grid.component.css +0 -274
- package/src/lib/components/advanced-table/parts/table-grid/table-grid.component.html +0 -168
- package/src/lib/components/advanced-table/parts/table-grid/table-grid.component.ts +0 -224
- package/src/lib/components/advanced-table/parts/table-modal-image/table-modal-image.component.css +0 -49
- package/src/lib/components/advanced-table/parts/table-modal-image/table-modal-image.component.html +0 -14
- package/src/lib/components/advanced-table/parts/table-modal-image/table-modal-image.component.ts +0 -22
- package/src/lib/components/advanced-table/parts/table-pagination/table-pagination.component.css +0 -147
- package/src/lib/components/advanced-table/parts/table-pagination/table-pagination.component.html +0 -95
- package/src/lib/components/advanced-table/parts/table-pagination/table-pagination.component.ts +0 -61
- package/src/lib/components/advanced-table/parts/table-toolbar/table-toolbar.component.css +0 -32
- package/src/lib/components/advanced-table/parts/table-toolbar/table-toolbar.component.html +0 -17
- package/src/lib/components/advanced-table/parts/table-toolbar/table-toolbar.component.ts +0 -30
- package/src/lib/components/advanced-table/types/index.ts +0 -2
- package/src/lib/components/advanced-table/types/table.types.ts +0 -101
- package/src/lib/components/advanced-table/types/time-zone.types.ts +0 -91
- package/src/lib/components/index.ts +0 -2
- package/src/public-api.ts +0 -4
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
import { Component, computed, effect, input, output, signal } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
CellDataType,
|
|
4
|
-
PagerItem,
|
|
5
|
-
RowId,
|
|
6
|
-
TableActionEvent,
|
|
7
|
-
TableColumn,
|
|
8
|
-
TableConfig,
|
|
9
|
-
TableSortState,
|
|
10
|
-
} from './types/table.types';
|
|
11
|
-
import { TableModalImageComponent } from './parts/table-modal-image/table-modal-image.component';
|
|
12
|
-
import { TableGridComponent } from './parts/table-grid/table-grid.component';
|
|
13
|
-
import { TablePaginationComponent } from './parts/table-pagination/table-pagination.component';
|
|
14
|
-
import { TableToolbarComponent } from './parts/table-toolbar/table-toolbar.component';
|
|
15
|
-
|
|
16
|
-
@Component({
|
|
17
|
-
selector: 'advanced-table',
|
|
18
|
-
imports: [
|
|
19
|
-
TableModalImageComponent,
|
|
20
|
-
TableGridComponent,
|
|
21
|
-
TablePaginationComponent,
|
|
22
|
-
TableToolbarComponent,
|
|
23
|
-
],
|
|
24
|
-
templateUrl: './advanced-table.component.html',
|
|
25
|
-
styleUrl: './advanced-table.component.css',
|
|
26
|
-
})
|
|
27
|
-
export class AdvancedTable<T extends Record<string, any>> {
|
|
28
|
-
// Inputs
|
|
29
|
-
readonly columns = input<TableColumn<T>[]>([]);
|
|
30
|
-
readonly data = input<T[]>([]);
|
|
31
|
-
readonly config = input<TableConfig>({
|
|
32
|
-
globalSearch: true,
|
|
33
|
-
columnFilters: false,
|
|
34
|
-
selectable: false,
|
|
35
|
-
selectionMode: 'multiple',
|
|
36
|
-
pagination: { enabled: false, pageSize: 10, pageSizeOptions: [10, 25, 50] },
|
|
37
|
-
scroll: { mode: 'none' },
|
|
38
|
-
emptyText: 'Sin resultados',
|
|
39
|
-
rowIdKey: 'id',
|
|
40
|
-
globalSearchVisibleOnly: true,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Outputs
|
|
44
|
-
readonly rowClick = output<T>();
|
|
45
|
-
readonly selectionChange = output<RowId[]>();
|
|
46
|
-
readonly actionClick = output<TableActionEvent<T>>();
|
|
47
|
-
|
|
48
|
-
// Signals
|
|
49
|
-
readonly globalQuery = signal<string>('');
|
|
50
|
-
readonly columnQueries = signal<Record<string, string>>({});
|
|
51
|
-
readonly sortState = signal<TableSortState | null>(null);
|
|
52
|
-
readonly page = signal<number>(1);
|
|
53
|
-
readonly visibleCount = signal<number>(0);
|
|
54
|
-
readonly modalOpen = signal<boolean>(false);
|
|
55
|
-
readonly modalImageSrc = signal<string>('');
|
|
56
|
-
readonly modalImageAlt = signal<string>('');
|
|
57
|
-
readonly selectedIdsSet = signal<Set<RowId>>(new Set<RowId>());
|
|
58
|
-
readonly pageSize = signal<number>(this.config().pagination?.pageSize ?? 10);
|
|
59
|
-
|
|
60
|
-
// Computed Data
|
|
61
|
-
readonly selectedIds = computed<RowId[]>(() => Array.from(this.selectedIdsSet()));
|
|
62
|
-
readonly visibleColumns = computed(() => (this.columns() ?? []).filter((c) => !c.hidden));
|
|
63
|
-
readonly showSelectionColumn = computed(() => !!this.config().selectable);
|
|
64
|
-
readonly gridTemplateColumns = computed(() => {
|
|
65
|
-
const cols: string[] = [];
|
|
66
|
-
|
|
67
|
-
if (this.showSelectionColumn()) cols.push('48px'); // selección
|
|
68
|
-
|
|
69
|
-
for (const c of this.visibleColumns()) {
|
|
70
|
-
cols.push(this.sizeToCss(c.size));
|
|
71
|
-
}
|
|
72
|
-
return cols.join(' ');
|
|
73
|
-
});
|
|
74
|
-
readonly filteredData = computed(() => {
|
|
75
|
-
const rows = this.data() ?? [];
|
|
76
|
-
const colsAll = this.columns() ?? [];
|
|
77
|
-
const colsVisible = this.visibleColumns();
|
|
78
|
-
const config = this.config();
|
|
79
|
-
|
|
80
|
-
const globalQuery = this.globalQuery().trim().toLowerCase();
|
|
81
|
-
const columnQueries = this.columnQueries();
|
|
82
|
-
|
|
83
|
-
const colsForGlobal =
|
|
84
|
-
(config.globalSearchVisibleOnly ?? true) ? colsVisible : colsAll.filter((c) => !c.hidden);
|
|
85
|
-
|
|
86
|
-
return rows.filter((row) => {
|
|
87
|
-
// column filters (AND)
|
|
88
|
-
for (const [key, q] of Object.entries(columnQueries)) {
|
|
89
|
-
const query = (q ?? '').trim().toLowerCase();
|
|
90
|
-
if (!query) continue;
|
|
91
|
-
|
|
92
|
-
const col = colsAll.find((c) => c.key === key);
|
|
93
|
-
if (!col) continue;
|
|
94
|
-
|
|
95
|
-
const value = this.getCellValue(row, col);
|
|
96
|
-
const text = this.valueToSearchableText(value, col.type, row).toLowerCase();
|
|
97
|
-
|
|
98
|
-
if (!text.includes(query)) return false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// global search (OR across columns)
|
|
102
|
-
if (config.globalSearch && globalQuery) {
|
|
103
|
-
let any = false;
|
|
104
|
-
for (const col of colsForGlobal) {
|
|
105
|
-
const value = this.getCellValue(row, col);
|
|
106
|
-
const text = this.valueToSearchableText(value, col.type, row).toLowerCase();
|
|
107
|
-
if (text.includes(globalQuery)) {
|
|
108
|
-
any = true;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!any) return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return true;
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
readonly sortedData = computed(() => {
|
|
119
|
-
const data = [...this.filteredData()];
|
|
120
|
-
const sort = this.sortState();
|
|
121
|
-
if (!sort) return data;
|
|
122
|
-
|
|
123
|
-
const col = (this.columns() ?? []).find((c) => c.key === sort.key);
|
|
124
|
-
if (!col) return data;
|
|
125
|
-
|
|
126
|
-
const dir = sort.dir === 'asc' ? 1 : -1;
|
|
127
|
-
|
|
128
|
-
data.sort((a, b) => {
|
|
129
|
-
const va = this.getCellValue(a, col);
|
|
130
|
-
const vb = this.getCellValue(b, col);
|
|
131
|
-
return dir * this.compareValues(va, vb, col.type);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return data;
|
|
135
|
-
});
|
|
136
|
-
readonly pagedData = computed(() => {
|
|
137
|
-
const config = this.config();
|
|
138
|
-
const rows = this.sortedData();
|
|
139
|
-
const fixedN = config.fixedRowCount;
|
|
140
|
-
const cappedRows = typeof fixedN === 'number' && fixedN > 0 ? rows.slice(0, fixedN) : rows;
|
|
141
|
-
|
|
142
|
-
const mode = config.scroll?.mode ?? 'none';
|
|
143
|
-
if (mode === 'infinite') {
|
|
144
|
-
return cappedRows.slice(0, this.visibleCount());
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// pagination
|
|
148
|
-
if (config.pagination?.enabled) {
|
|
149
|
-
const size = this.pageSize();
|
|
150
|
-
const page = this.page();
|
|
151
|
-
const start = (page - 1) * size;
|
|
152
|
-
return cappedRows.slice(start, start + size);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return cappedRows;
|
|
156
|
-
});
|
|
157
|
-
readonly pagerItems = computed<PagerItem[]>(() => {
|
|
158
|
-
const config = this.config();
|
|
159
|
-
if (!config.pagination?.enabled) return [];
|
|
160
|
-
|
|
161
|
-
const totalPages = this.pageCount();
|
|
162
|
-
const current = this.page();
|
|
163
|
-
|
|
164
|
-
if (totalPages <= 1) return [];
|
|
165
|
-
|
|
166
|
-
if (totalPages <= 7) {
|
|
167
|
-
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const items: PagerItem[] = [];
|
|
171
|
-
const first = 1;
|
|
172
|
-
const last = totalPages;
|
|
173
|
-
const around = 1;
|
|
174
|
-
|
|
175
|
-
const start = Math.max(2, current - around);
|
|
176
|
-
const end = Math.min(last - 1, current + around);
|
|
177
|
-
|
|
178
|
-
items.push(first);
|
|
179
|
-
|
|
180
|
-
if (start > 2) items.push('…');
|
|
181
|
-
|
|
182
|
-
for (let p = start; p <= end; p++) {
|
|
183
|
-
items.push(p);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (end < last - 1) items.push('…');
|
|
187
|
-
|
|
188
|
-
items.push(last);
|
|
189
|
-
|
|
190
|
-
return items;
|
|
191
|
-
});
|
|
192
|
-
readonly totalCount = computed(() => this.sortedData().length);
|
|
193
|
-
readonly pageCount = computed(() => {
|
|
194
|
-
const config = this.config();
|
|
195
|
-
if (!config.pagination?.enabled) return 1;
|
|
196
|
-
return Math.max(1, Math.ceil(this.totalCount() / this.pageSize()));
|
|
197
|
-
});
|
|
198
|
-
readonly isAllSelectedOnPage = computed(() => {
|
|
199
|
-
if (!this.showSelectionColumn()) return false;
|
|
200
|
-
const ids = this.pagedData().map((r) => this.getRowId(r));
|
|
201
|
-
if (ids.length === 0) return false;
|
|
202
|
-
|
|
203
|
-
const set = this.selectedIdsSet();
|
|
204
|
-
return ids.every((id) => set.has(id));
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Effects
|
|
208
|
-
infiniteScrollEffect = effect(() => {
|
|
209
|
-
const config = this.config();
|
|
210
|
-
const mode = config.scroll?.mode ?? 'none';
|
|
211
|
-
const batch = config.scroll?.batchSize ?? 50;
|
|
212
|
-
|
|
213
|
-
if (mode === 'infinite') {
|
|
214
|
-
this.visibleCount.set(batch);
|
|
215
|
-
} else {
|
|
216
|
-
this.visibleCount.set(Number.MAX_SAFE_INTEGER);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
selectionDataEffect = effect(() => {
|
|
220
|
-
this.selectionChange.emit(this.selectedIds());
|
|
221
|
-
});
|
|
222
|
-
pagesCountEffect = effect(() => {
|
|
223
|
-
const totalPages = this.pageCount();
|
|
224
|
-
if (this.page() > totalPages) {
|
|
225
|
-
this.page.set(totalPages);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// UI Actions
|
|
230
|
-
onHeaderClickSort(col: TableColumn<T>) {
|
|
231
|
-
if (!col.sortable) return;
|
|
232
|
-
const current = this.sortState();
|
|
233
|
-
if (!current || current.key !== col.key) {
|
|
234
|
-
this.sortState.set({ key: col.key, dir: 'asc' });
|
|
235
|
-
} else if (current.dir === 'asc') {
|
|
236
|
-
this.sortState.set({ key: col.key, dir: 'desc' });
|
|
237
|
-
} else {
|
|
238
|
-
this.sortState.set(null);
|
|
239
|
-
}
|
|
240
|
-
this.page.set(1);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
onBodyScroll(event: Event) {
|
|
244
|
-
const config = this.config();
|
|
245
|
-
if ((config.scroll?.mode ?? 'none') !== 'infinite') return;
|
|
246
|
-
|
|
247
|
-
const el = event.target as HTMLElement;
|
|
248
|
-
const thresholdPx = 120;
|
|
249
|
-
const nearBottom = el.scrollTop + el.clientHeight >= el.scrollHeight - thresholdPx;
|
|
250
|
-
|
|
251
|
-
if (!nearBottom) return;
|
|
252
|
-
|
|
253
|
-
const batch = config.scroll?.batchSize ?? 50;
|
|
254
|
-
const next = Math.min(this.sortedData().length, this.visibleCount() + batch);
|
|
255
|
-
this.visibleCount.set(next);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
onPageSizeChange(size: number) {
|
|
259
|
-
if (!Number.isFinite(size) || size <= 0) return;
|
|
260
|
-
this.pageSize.set(size);
|
|
261
|
-
this.page.set(1);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
getCellValue(row: T, col: TableColumn<T>): unknown {
|
|
265
|
-
try {
|
|
266
|
-
return col.valueGetter ? col.valueGetter(row) : row?.[col.key];
|
|
267
|
-
} catch {
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
getRowId(row: T): RowId {
|
|
273
|
-
const config = this.config();
|
|
274
|
-
if (config.rowIdGetter) return config.rowIdGetter(row) as RowId;
|
|
275
|
-
|
|
276
|
-
const key = config.rowIdKey ?? 'id';
|
|
277
|
-
const value = row?.[key];
|
|
278
|
-
return (value ?? JSON.stringify(row)) as RowId;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
setGlobalQuery(query: string) {
|
|
282
|
-
this.globalQuery.set(query ?? '');
|
|
283
|
-
this.page.set(1);
|
|
284
|
-
this.resetInfiniteIfNeeded();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
setColumnQuery(key: string, query: string) {
|
|
288
|
-
const next = { ...this.columnQueries() };
|
|
289
|
-
next[key] = query ?? '';
|
|
290
|
-
this.columnQueries.set(next);
|
|
291
|
-
this.page.set(1);
|
|
292
|
-
this.resetInfiniteIfNeeded();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
clearFilters() {
|
|
296
|
-
this.globalQuery.set('');
|
|
297
|
-
this.columnQueries.set({});
|
|
298
|
-
this.page.set(1);
|
|
299
|
-
this.resetInfiniteIfNeeded();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
onRowClick(row: T) {
|
|
303
|
-
this.rowClick.emit(row);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
toggleRowSelection(row: T) {
|
|
307
|
-
const config = this.config();
|
|
308
|
-
if (!config.selectable) return;
|
|
309
|
-
|
|
310
|
-
const id = this.getRowId(row);
|
|
311
|
-
const mode = config.selectionMode ?? 'multiple';
|
|
312
|
-
|
|
313
|
-
const set = new Set(this.selectedIdsSet());
|
|
314
|
-
if (mode === 'single') {
|
|
315
|
-
if (set.has(id)) set.clear();
|
|
316
|
-
else {
|
|
317
|
-
set.clear();
|
|
318
|
-
set.add(id);
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
if (set.has(id)) set.delete(id);
|
|
322
|
-
else set.add(id);
|
|
323
|
-
}
|
|
324
|
-
this.selectedIdsSet.set(set);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
toggleSelectAllOnPage() {
|
|
328
|
-
const config = this.config();
|
|
329
|
-
if (!config.selectable) return;
|
|
330
|
-
if ((config.selectionMode ?? 'multiple') === 'single') return;
|
|
331
|
-
|
|
332
|
-
const ids = this.pagedData().map((r) => this.getRowId(r));
|
|
333
|
-
const set = new Set(this.selectedIdsSet());
|
|
334
|
-
|
|
335
|
-
const allSelected = ids.every((id) => set.has(id));
|
|
336
|
-
if (allSelected) ids.forEach((id) => set.delete(id));
|
|
337
|
-
else ids.forEach((id) => set.add(id));
|
|
338
|
-
|
|
339
|
-
this.selectedIdsSet.set(set);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
prevPage() {
|
|
343
|
-
this.page.set(Math.max(1, this.page() - 1));
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
nextPage() {
|
|
347
|
-
this.page.set(Math.min(this.pageCount(), this.page() + 1));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
goToPage(p: number) {
|
|
351
|
-
const clamped = Math.max(1, Math.min(this.pageCount(), p));
|
|
352
|
-
this.page.set(clamped);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
openImageModal(src: string, alt: string) {
|
|
356
|
-
this.modalImageSrc.set(src);
|
|
357
|
-
this.modalImageAlt.set(alt);
|
|
358
|
-
this.modalOpen.set(true);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
closeModal() {
|
|
362
|
-
this.modalOpen.set(false);
|
|
363
|
-
this.modalImageSrc.set('');
|
|
364
|
-
this.modalImageAlt.set('');
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Private functions
|
|
368
|
-
private resetInfiniteIfNeeded() {
|
|
369
|
-
const config = this.config();
|
|
370
|
-
if ((config.scroll?.mode ?? 'none') !== 'infinite') return;
|
|
371
|
-
const batch = config.scroll?.batchSize ?? 50;
|
|
372
|
-
this.visibleCount.set(batch);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
private sizeToCss(size?: string): string {
|
|
376
|
-
switch (size) {
|
|
377
|
-
case 'XS':
|
|
378
|
-
return '80px';
|
|
379
|
-
case 'SM':
|
|
380
|
-
return '120px';
|
|
381
|
-
case 'MD':
|
|
382
|
-
return '180px';
|
|
383
|
-
case 'LG':
|
|
384
|
-
return '260px';
|
|
385
|
-
case 'XL':
|
|
386
|
-
return '360px';
|
|
387
|
-
case 'AUTO':
|
|
388
|
-
default:
|
|
389
|
-
return '1fr';
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
private toNumber(value: unknown): number {
|
|
394
|
-
if (typeof value === 'number') return value;
|
|
395
|
-
if (typeof value === 'string') {
|
|
396
|
-
return Number(value.replace(/,/g, '').trim());
|
|
397
|
-
}
|
|
398
|
-
return Number.NaN;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
private toDate(value: unknown): Date | null {
|
|
402
|
-
if (value instanceof Date && !Number.isNaN(value.getTime())) return value;
|
|
403
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
404
|
-
const date = new Date(value);
|
|
405
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
406
|
-
}
|
|
407
|
-
return null;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
private compareValues(firstValue: unknown, secondValue: unknown, type: CellDataType): number {
|
|
411
|
-
const firstNull = firstValue == null || firstValue === '';
|
|
412
|
-
const secondNull = secondValue == null || secondValue === '';
|
|
413
|
-
if (firstNull && secondNull) return 0;
|
|
414
|
-
if (firstNull) return 1;
|
|
415
|
-
if (secondNull) return -1;
|
|
416
|
-
|
|
417
|
-
let response: number | null = null;
|
|
418
|
-
switch (type) {
|
|
419
|
-
case 'integer':
|
|
420
|
-
case 'decimal':
|
|
421
|
-
case 'currency': {
|
|
422
|
-
const firstNumber = this.toNumber(firstValue);
|
|
423
|
-
const secondNumber = this.toNumber(secondValue);
|
|
424
|
-
if (!Number.isFinite(firstNumber) && !Number.isFinite(secondNumber)) response = 0;
|
|
425
|
-
else if (!Number.isFinite(firstNumber)) response = 1;
|
|
426
|
-
else if (!Number.isFinite(secondNumber)) response = -1;
|
|
427
|
-
else response = firstNumber === secondNumber ? 0 : firstNumber < secondNumber ? -1 : 1;
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
case 'date':
|
|
432
|
-
case 'datetime': {
|
|
433
|
-
const firstDate = this.toDate(firstValue);
|
|
434
|
-
const toCompareDate = this.toDate(secondValue);
|
|
435
|
-
if (!firstDate && !toCompareDate) response = 0;
|
|
436
|
-
else if (!firstDate) response = 1;
|
|
437
|
-
else if (!toCompareDate) response = -1;
|
|
438
|
-
else {
|
|
439
|
-
const ta = firstDate.getTime();
|
|
440
|
-
const tb = toCompareDate.getTime();
|
|
441
|
-
response = ta === tb ? 0 : ta < tb ? -1 : 1;
|
|
442
|
-
}
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
case 'boolean': {
|
|
447
|
-
const firstBool = firstValue === true ? 1 : 0;
|
|
448
|
-
const secondBool = secondValue === true ? 1 : 0;
|
|
449
|
-
response = firstBool - secondBool;
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
default: {
|
|
454
|
-
const firstString = String(firstValue).toLowerCase();
|
|
455
|
-
const secondString = String(secondValue).toLowerCase();
|
|
456
|
-
response = firstString.localeCompare(secondString, 'es');
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return response;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
private valueToSearchableText(value: unknown, type: CellDataType, row: T): string {
|
|
464
|
-
if (value == null) return '';
|
|
465
|
-
if (type === 'image') return '';
|
|
466
|
-
if (type === 'boolean') return value === true ? 'si true yes 1' : 'no false 0';
|
|
467
|
-
return String(value);
|
|
468
|
-
}
|
|
469
|
-
}
|