@alaarab/ogrid-core 2.0.3 → 2.0.5
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/dist/esm/constants.js +2 -0
- package/dist/esm/utils/aggregationUtils.js +13 -3
- package/dist/esm/utils/clientSideData.js +55 -28
- package/dist/esm/utils/gridContextMenuHelpers.js +6 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/utils/gridContextMenuHelpers.d.ts +8 -0
- package/dist/types/utils/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/esm/constants.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/** Width of the row selection checkbox column in pixels. */
|
|
5
5
|
export const CHECKBOX_COLUMN_WIDTH = 48;
|
|
6
|
+
/** Width of the row numbers column in pixels. */
|
|
7
|
+
export const ROW_NUMBER_COLUMN_WIDTH = 50;
|
|
6
8
|
/** Default minimum width for resizable columns in pixels. */
|
|
7
9
|
export const DEFAULT_MIN_COLUMN_WIDTH = 80;
|
|
8
10
|
/** Horizontal padding inside cells, used for width calculations. */
|
|
@@ -30,12 +30,22 @@ export function computeAggregations(items, visibleCols, selectionRange) {
|
|
|
30
30
|
// Need at least 2 cells selected and at least 1 numeric value to show aggregation
|
|
31
31
|
if (totalCells < 2 || numericValues.length === 0)
|
|
32
32
|
return null;
|
|
33
|
-
|
|
33
|
+
let sum = 0;
|
|
34
|
+
let min = numericValues[0];
|
|
35
|
+
let max = numericValues[0];
|
|
36
|
+
for (let i = 0; i < numericValues.length; i++) {
|
|
37
|
+
const v = numericValues[i];
|
|
38
|
+
sum += v;
|
|
39
|
+
if (v < min)
|
|
40
|
+
min = v;
|
|
41
|
+
if (v > max)
|
|
42
|
+
max = v;
|
|
43
|
+
}
|
|
34
44
|
return {
|
|
35
45
|
sum,
|
|
36
46
|
avg: sum / numericValues.length,
|
|
37
|
-
min
|
|
38
|
-
max
|
|
47
|
+
min,
|
|
48
|
+
max,
|
|
39
49
|
count: numericValues.length,
|
|
40
50
|
};
|
|
41
51
|
}
|
|
@@ -12,6 +12,11 @@ import { getFilterField } from './ogridHelpers';
|
|
|
12
12
|
* @returns Filtered and sorted array
|
|
13
13
|
*/
|
|
14
14
|
export function processClientSideData(data, columns, filters, sortBy, sortDirection) {
|
|
15
|
+
// Build column lookup map for O(1) access by columnId
|
|
16
|
+
const columnMap = new Map();
|
|
17
|
+
for (let i = 0; i < columns.length; i++) {
|
|
18
|
+
columnMap.set(columns[i].columnId, columns[i]);
|
|
19
|
+
}
|
|
15
20
|
// --- Filtering (single-pass: build predicates, then one .filter()) ---
|
|
16
21
|
const predicates = [];
|
|
17
22
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -71,37 +76,59 @@ export function processClientSideData(data, columns, filters, sortBy, sortDirect
|
|
|
71
76
|
: data.slice();
|
|
72
77
|
// --- Sorting ---
|
|
73
78
|
if (sortBy) {
|
|
74
|
-
const sortCol =
|
|
79
|
+
const sortCol = columnMap.get(sortBy);
|
|
75
80
|
const compare = sortCol?.compare;
|
|
76
81
|
const dir = sortDirection === 'asc' ? 1 : -1;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return 1 * dir;
|
|
92
|
-
if (sortCol?.type === 'date') {
|
|
93
|
-
const at = new Date(String(av)).getTime();
|
|
94
|
-
const bt = new Date(String(bv)).getTime();
|
|
95
|
-
const aN = Number.isNaN(at) ? 0 : at;
|
|
96
|
-
const bN = Number.isNaN(bt) ? 0 : bt;
|
|
97
|
-
return aN === bN ? 0 : aN > bN ? dir : -dir;
|
|
82
|
+
const isDateSort = sortCol?.type === 'date';
|
|
83
|
+
// For date columns, pre-compute timestamps to avoid repeated new Date() in O(n log n) comparisons
|
|
84
|
+
if (isDateSort && !compare) {
|
|
85
|
+
const timestampCache = new Map();
|
|
86
|
+
for (let i = 0; i < rows.length; i++) {
|
|
87
|
+
const row = rows[i];
|
|
88
|
+
const val = sortCol ? getCellValue(row, sortCol) : row[sortBy];
|
|
89
|
+
if (val == null) {
|
|
90
|
+
timestampCache.set(row, NaN);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const t = new Date(String(val)).getTime();
|
|
94
|
+
timestampCache.set(row, Number.isNaN(t) ? 0 : t);
|
|
95
|
+
}
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
rows.sort((a, b) => {
|
|
98
|
+
const at = timestampCache.get(a);
|
|
99
|
+
const bt = timestampCache.get(b);
|
|
100
|
+
if (Number.isNaN(at) && Number.isNaN(bt))
|
|
101
|
+
return 0;
|
|
102
|
+
if (Number.isNaN(at))
|
|
103
|
+
return -1 * dir;
|
|
104
|
+
if (Number.isNaN(bt))
|
|
105
|
+
return 1 * dir;
|
|
106
|
+
return at === bt ? 0 : at > bt ? dir : -dir;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
rows.sort((a, b) => {
|
|
111
|
+
if (compare)
|
|
112
|
+
return compare(a, b) * dir;
|
|
113
|
+
const av = sortCol
|
|
114
|
+
? getCellValue(a, sortCol)
|
|
115
|
+
: a[sortBy];
|
|
116
|
+
const bv = sortCol
|
|
117
|
+
? getCellValue(b, sortCol)
|
|
118
|
+
: b[sortBy];
|
|
119
|
+
if (av == null && bv == null)
|
|
120
|
+
return 0;
|
|
121
|
+
if (av == null)
|
|
122
|
+
return -1 * dir;
|
|
123
|
+
if (bv == null)
|
|
124
|
+
return 1 * dir;
|
|
125
|
+
if (typeof av === 'number' && typeof bv === 'number')
|
|
126
|
+
return av === bv ? 0 : av > bv ? dir : -dir;
|
|
127
|
+
const as = String(av).toLowerCase();
|
|
128
|
+
const bs = String(bv).toLowerCase();
|
|
129
|
+
return as === bs ? 0 : as > bs ? dir : -dir;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
105
132
|
}
|
|
106
133
|
return rows;
|
|
107
134
|
}
|
|
@@ -44,3 +44,9 @@ export function getContextMenuHandlers(props) {
|
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
/** Column header menu items for pin/unpin actions. */
|
|
48
|
+
export const COLUMN_HEADER_MENU_ITEMS = [
|
|
49
|
+
{ id: 'pinLeft', label: 'Pin left' },
|
|
50
|
+
{ id: 'pinRight', label: 'Pin right' },
|
|
51
|
+
{ id: 'unpin', label: 'Unpin' },
|
|
52
|
+
];
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelec
|
|
|
5
5
|
export { getStatusBarParts } from './statusBarHelpers';
|
|
6
6
|
export { getDataGridStatusBarConfig } from './dataGridStatusBar';
|
|
7
7
|
export { getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, } from './paginationHelpers';
|
|
8
|
-
export { GRID_CONTEXT_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
|
|
8
|
+
export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
|
|
9
9
|
export { parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, } from './valueParsers';
|
|
10
10
|
export { computeAggregations } from './aggregationUtils';
|
|
11
11
|
export { processClientSideData } from './clientSideData';
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/** Width of the row selection checkbox column in pixels. */
|
|
5
5
|
export declare const CHECKBOX_COLUMN_WIDTH = 48;
|
|
6
|
+
/** Width of the row numbers column in pixels. */
|
|
7
|
+
export declare const ROW_NUMBER_COLUMN_WIDTH = 50;
|
|
6
8
|
/** Default minimum width for resizable columns in pixels. */
|
|
7
9
|
export declare const DEFAULT_MIN_COLUMN_WIDTH = 80;
|
|
8
10
|
/** Horizontal padding inside cells, used for width calculations. */
|
|
@@ -29,3 +29,11 @@ export interface GridContextMenuHandlerProps {
|
|
|
29
29
|
* action and then onClose. Used by Fluent, Material, and Radix GridContextMenu components.
|
|
30
30
|
*/
|
|
31
31
|
export declare function getContextMenuHandlers(props: GridContextMenuHandlerProps): Record<string, () => void>;
|
|
32
|
+
/** Column header menu item definition. */
|
|
33
|
+
export interface IColumnHeaderMenuItem {
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
icon?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Column header menu items for pin/unpin actions. */
|
|
39
|
+
export declare const COLUMN_HEADER_MENU_ITEMS: IColumnHeaderMenuItem[];
|
|
@@ -6,10 +6,10 @@ export { getStatusBarParts } from './statusBarHelpers';
|
|
|
6
6
|
export { getDataGridStatusBarConfig } from './dataGridStatusBar';
|
|
7
7
|
export { getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, } from './paginationHelpers';
|
|
8
8
|
export type { PaginationViewModel } from './paginationHelpers';
|
|
9
|
-
export { GRID_CONTEXT_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
|
|
9
|
+
export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
|
|
10
10
|
export type { CsvColumn } from './exportToCsv';
|
|
11
11
|
export type { StatusBarPart, StatusBarPartsInput } from './statusBarHelpers';
|
|
12
|
-
export type { GridContextMenuItem, GridContextMenuHandlerProps } from './gridContextMenuHelpers';
|
|
12
|
+
export type { GridContextMenuItem, IColumnHeaderMenuItem, GridContextMenuHandlerProps } from './gridContextMenuHelpers';
|
|
13
13
|
export { parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, } from './valueParsers';
|
|
14
14
|
export type { ParseValueResult } from './valueParsers';
|
|
15
15
|
export { computeAggregations } from './aggregationUtils';
|
package/package.json
CHANGED