@opencorestack/opengridx 0.1.8 → 0.1.9
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/CHANGELOG.md +16 -0
- package/dist/opengridx.es.js +3485 -3370
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +11 -11
- package/dist/opengridx.umd.js.map +1 -1
- package/lib/components/Cell/Cell.tsx +53 -55
- package/lib/components/DataGrid/DataGrid.smoke.test.tsx +58 -0
- package/lib/components/DataGrid/DataGrid.tsx +65 -641
- package/lib/components/Row/Row.tsx +39 -38
- package/lib/components/Toolbar/GlobalSearch.tsx +1 -1
- package/lib/components/Toolbar/GridToolbar.tsx +20 -5
- package/lib/components/Toolbar/PivotPanel.tsx +7 -2
- package/lib/components/ui/DragHandleIcon.tsx +1 -1
- package/lib/hooks/core/useDataGrid.ts +2 -2
- package/lib/hooks/core/useGridKeyboardNavigation.ts +371 -0
- package/lib/hooks/core/useLayout.ts +354 -0
- package/lib/hooks/features/useAggregation.test.ts +135 -0
- package/lib/hooks/features/useGridClipboard.ts +1 -1
- package/lib/hooks/features/useGridDataSource.ts +1 -1
- package/lib/state/useGridStateStorage.ts +1 -1
- package/lib/utils/export/index.ts +1 -1
- package/lib/utils/filtering/filtering.test.ts +178 -0
- package/lib/utils/sorting/sorting.test.ts +88 -0
- package/package.json +12 -5
- package/lib/utils/virtualization/index.ts +0 -106
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { filterRows, applyFilterItem, applyQuickFilter, FILTER_OPERATORS } from './index';
|
|
3
|
+
import type { GridFilterItem } from '../../types';
|
|
4
|
+
|
|
5
|
+
const ROWS = [
|
|
6
|
+
{ id: 1, name: 'Alice', age: 30, active: true, department: 'Engineering' },
|
|
7
|
+
{ id: 2, name: 'Bob', age: 25, active: false, department: 'Marketing' },
|
|
8
|
+
{ id: 3, name: 'Charlie', age: 35, active: true, department: 'Engineering' },
|
|
9
|
+
{ id: 4, name: 'Diana', age: null, active: false, department: null },
|
|
10
|
+
{ id: 5, name: 'Eve', age: 28, active: true, department: 'Marketing' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
describe('FILTER_OPERATORS', () => {
|
|
14
|
+
describe('contains', () => {
|
|
15
|
+
it('matches substring case-insensitively', () => {
|
|
16
|
+
expect(FILTER_OPERATORS.contains('Alice', 'ali')).toBe(true);
|
|
17
|
+
expect(FILTER_OPERATORS.contains('Alice', 'Bob')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it('returns false for null values', () => {
|
|
20
|
+
expect(FILTER_OPERATORS.contains(null, 'x')).toBe(false);
|
|
21
|
+
expect(FILTER_OPERATORS.contains('x', null)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('equals', () => {
|
|
26
|
+
it('matches case-insensitively', () => {
|
|
27
|
+
expect(FILTER_OPERATORS.equals('Alice', 'alice')).toBe(true);
|
|
28
|
+
expect(FILTER_OPERATORS.equals('Alice', 'Bob')).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it('returns true for both null', () => {
|
|
31
|
+
expect(FILTER_OPERATORS.equals(null, null)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('startsWith / endsWith', () => {
|
|
36
|
+
it('startsWith matches prefix', () => {
|
|
37
|
+
expect(FILTER_OPERATORS.startsWith('Alice', 'Ali')).toBe(true);
|
|
38
|
+
expect(FILTER_OPERATORS.startsWith('Alice', 'ice')).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it('endsWith matches suffix', () => {
|
|
41
|
+
expect(FILTER_OPERATORS.endsWith('Alice', 'ice')).toBe(true);
|
|
42
|
+
expect(FILTER_OPERATORS.endsWith('Alice', 'Ali')).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('isEmpty / isNotEmpty', () => {
|
|
47
|
+
it('isEmpty detects null, undefined, empty string, whitespace', () => {
|
|
48
|
+
expect(FILTER_OPERATORS.isEmpty(null)).toBe(true);
|
|
49
|
+
expect(FILTER_OPERATORS.isEmpty(undefined)).toBe(true);
|
|
50
|
+
expect(FILTER_OPERATORS.isEmpty('')).toBe(true);
|
|
51
|
+
expect(FILTER_OPERATORS.isEmpty(' ')).toBe(true);
|
|
52
|
+
expect(FILTER_OPERATORS.isEmpty('x')).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
it('isNotEmpty is the inverse', () => {
|
|
55
|
+
expect(FILTER_OPERATORS.isNotEmpty('x')).toBe(true);
|
|
56
|
+
expect(FILTER_OPERATORS.isNotEmpty(null)).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('numeric comparisons', () => {
|
|
61
|
+
it('> returns true when value exceeds filter', () => {
|
|
62
|
+
expect(FILTER_OPERATORS['>'](30, 25)).toBe(true);
|
|
63
|
+
expect(FILTER_OPERATORS['>'](25, 30)).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it('>= includes equality', () => {
|
|
66
|
+
expect(FILTER_OPERATORS['>='](30, 30)).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('< and <= work symmetrically', () => {
|
|
69
|
+
expect(FILTER_OPERATORS['<'](20, 30)).toBe(true);
|
|
70
|
+
expect(FILTER_OPERATORS['<='](30, 30)).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
it('returns false for non-numeric values', () => {
|
|
73
|
+
expect(FILTER_OPERATORS['>'](NaN, 10)).toBe(false);
|
|
74
|
+
expect(FILTER_OPERATORS['>'](10, NaN)).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('isAnyOf', () => {
|
|
79
|
+
it('matches any value in the array', () => {
|
|
80
|
+
expect(FILTER_OPERATORS.isAnyOf('Engineering', ['Engineering', 'Finance'])).toBe(true);
|
|
81
|
+
expect(FILTER_OPERATORS.isAnyOf('HR', ['Engineering', 'Finance'])).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it('returns false for non-array filterValue', () => {
|
|
84
|
+
expect(FILTER_OPERATORS.isAnyOf('x', null as unknown as [])).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('applyFilterItem', () => {
|
|
90
|
+
it('returns true for matching field/operator/value', () => {
|
|
91
|
+
const row = { id: 1, name: 'Alice', age: 30 };
|
|
92
|
+
expect(applyFilterItem(row, { field: 'name', operator: 'contains', value: 'ali' })).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns false for non-matching', () => {
|
|
96
|
+
const row = { id: 1, name: 'Alice', age: 30 };
|
|
97
|
+
expect(applyFilterItem(row, { field: 'name', operator: 'contains', value: 'bob' })).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('returns true and warns for unknown operator', () => {
|
|
101
|
+
const row = { id: 1, name: 'Alice' };
|
|
102
|
+
// Unknown operator → falls through to true (lenient)
|
|
103
|
+
expect(applyFilterItem(row, { field: 'name', operator: 'unknownOp', value: 'x' } as unknown as GridFilterItem)).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('applyQuickFilter', () => {
|
|
108
|
+
it('returns true when empty quickFilterValues', () => {
|
|
109
|
+
expect(applyQuickFilter({ id: 1, name: 'Alice' }, [])).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
it('matches all terms (AND logic)', () => {
|
|
112
|
+
const row = { id: 1, name: 'Alice', department: 'Engineering' };
|
|
113
|
+
expect(applyQuickFilter(row, ['alice', 'eng'])).toBe(true);
|
|
114
|
+
expect(applyQuickFilter(row, ['alice', 'marketing'])).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
it('ignores null field values', () => {
|
|
117
|
+
expect(applyQuickFilter({ id: 1, name: null }, ['x'])).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('filterRows', () => {
|
|
122
|
+
it('returns all rows when filterModel is empty', () => {
|
|
123
|
+
const result = filterRows(ROWS, { items: [] });
|
|
124
|
+
expect(result).toHaveLength(ROWS.length);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('filters by single contains item', () => {
|
|
128
|
+
const result = filterRows(ROWS, {
|
|
129
|
+
items: [{ field: 'name', operator: 'contains', value: 'a' }],
|
|
130
|
+
});
|
|
131
|
+
// Alice, Charlie, Diana
|
|
132
|
+
expect(result.map(r => r.name)).toEqual(expect.arrayContaining(['Alice', 'Charlie', 'Diana']));
|
|
133
|
+
expect(result).toHaveLength(3);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('applies AND logic across multiple items', () => {
|
|
137
|
+
const result = filterRows(ROWS, {
|
|
138
|
+
items: [
|
|
139
|
+
{ field: 'department', operator: 'equals', value: 'Engineering' },
|
|
140
|
+
{ field: 'age', operator: '>', value: 30 },
|
|
141
|
+
],
|
|
142
|
+
logicOperator: 'and',
|
|
143
|
+
});
|
|
144
|
+
expect(result.map(r => r.name)).toEqual(['Charlie']);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('applies OR logic across multiple items', () => {
|
|
148
|
+
const result = filterRows(ROWS, {
|
|
149
|
+
items: [
|
|
150
|
+
{ field: 'name', operator: 'equals', value: 'Alice' },
|
|
151
|
+
{ field: 'name', operator: 'equals', value: 'Eve' },
|
|
152
|
+
],
|
|
153
|
+
logicOperator: 'or',
|
|
154
|
+
});
|
|
155
|
+
expect(result.map(r => r.name)).toEqual(expect.arrayContaining(['Alice', 'Eve']));
|
|
156
|
+
expect(result).toHaveLength(2);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('applies quickFilterValues (global search)', () => {
|
|
160
|
+
const result = filterRows(ROWS, {
|
|
161
|
+
items: [],
|
|
162
|
+
quickFilterValues: ['engineering'],
|
|
163
|
+
});
|
|
164
|
+
expect(result.map(r => r.name)).toEqual(expect.arrayContaining(['Alice', 'Charlie']));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('handles null field values without throwing', () => {
|
|
168
|
+
const result = filterRows(ROWS, {
|
|
169
|
+
items: [{ field: 'department', operator: 'isEmpty' }],
|
|
170
|
+
});
|
|
171
|
+
expect(result.map(r => r.name)).toEqual(['Diana']);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('returns same reference when no filter items and no quickfilter', () => {
|
|
175
|
+
const result = filterRows(ROWS, { items: [], quickFilterValues: [] });
|
|
176
|
+
expect(result).toBe(ROWS);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { sortRows, compareValues } from './index';
|
|
3
|
+
|
|
4
|
+
describe('compareValues', () => {
|
|
5
|
+
describe('null handling', () => {
|
|
6
|
+
it('null === null → 0', () => expect(compareValues(null, null, 'asc')).toBe(0));
|
|
7
|
+
it('null sorts last in asc', () => expect(compareValues(null, 1, 'asc')).toBeGreaterThan(0));
|
|
8
|
+
it('null sorts first in desc', () => expect(compareValues(null, 1, 'desc')).toBeLessThan(0));
|
|
9
|
+
it('non-null before null in asc', () => expect(compareValues(1, null, 'asc')).toBeLessThan(0));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('numbers', () => {
|
|
13
|
+
it('asc: smaller first', () => expect(compareValues(1, 2, 'asc')).toBeLessThan(0));
|
|
14
|
+
it('desc: larger first', () => expect(compareValues(2, 1, 'desc')).toBeLessThan(0));
|
|
15
|
+
it('equal numbers → 0', () => expect(compareValues(5, 5, 'asc')).toBe(0));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('dates', () => {
|
|
19
|
+
const d1 = new Date('2023-01-01');
|
|
20
|
+
const d2 = new Date('2024-01-01');
|
|
21
|
+
it('asc: earlier date first', () => expect(compareValues(d1, d2, 'asc')).toBeLessThan(0));
|
|
22
|
+
it('desc: later date first', () => expect(compareValues(d2, d1, 'desc')).toBeLessThan(0));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('strings', () => {
|
|
26
|
+
it('asc: lexicographic order', () => expect(compareValues('apple', 'banana', 'asc')).toBeLessThan(0));
|
|
27
|
+
it('desc: reversed order', () => expect(compareValues('banana', 'apple', 'desc')).toBeLessThan(0));
|
|
28
|
+
it('case-insensitive', () => expect(compareValues('APPLE', 'apple', 'asc')).toBe(0));
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('sortRows', () => {
|
|
33
|
+
const ROWS = [
|
|
34
|
+
{ id: 3, name: 'Charlie', age: 35, dept: 'Engineering' },
|
|
35
|
+
{ id: 1, name: 'Alice', age: 30, dept: 'Marketing' },
|
|
36
|
+
{ id: 4, name: 'Diana', age: 25, dept: 'Engineering' },
|
|
37
|
+
{ id: 2, name: 'Bob', age: 30, dept: 'Marketing' },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
it('returns same reference when sortModel is empty', () => {
|
|
41
|
+
const result = sortRows(ROWS, []);
|
|
42
|
+
expect(result).toBe(ROWS);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('does not mutate the original array', () => {
|
|
46
|
+
const original = [...ROWS];
|
|
47
|
+
sortRows(ROWS, [{ field: 'name', sort: 'asc' }]);
|
|
48
|
+
expect(ROWS).toEqual(original);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('sorts by single field asc', () => {
|
|
52
|
+
const result = sortRows(ROWS, [{ field: 'name', sort: 'asc' }]);
|
|
53
|
+
expect(result.map(r => r.name)).toEqual(['Alice', 'Bob', 'Charlie', 'Diana']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('sorts by single field desc', () => {
|
|
57
|
+
const result = sortRows(ROWS, [{ field: 'age', sort: 'desc' }]);
|
|
58
|
+
expect(result.map(r => r.age)).toEqual([35, 30, 30, 25]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('applies multi-field sort (age asc, name asc for ties)', () => {
|
|
62
|
+
const result = sortRows(ROWS, [
|
|
63
|
+
{ field: 'age', sort: 'asc' },
|
|
64
|
+
{ field: 'name', sort: 'asc' },
|
|
65
|
+
]);
|
|
66
|
+
expect(result.map(r => r.name)).toEqual(['Diana', 'Alice', 'Bob', 'Charlie']);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('handles null values — nulls sort last in asc', () => {
|
|
70
|
+
const rowsWithNull = [
|
|
71
|
+
{ id: 1, name: 'Alice', age: 30 },
|
|
72
|
+
{ id: 2, name: null, age: 25 },
|
|
73
|
+
{ id: 3, name: 'Bob', age: 35 },
|
|
74
|
+
];
|
|
75
|
+
const result = sortRows(rowsWithNull, [{ field: 'name', sort: 'asc' }]);
|
|
76
|
+
expect(result[result.length - 1].name).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('handles rows with identical values — stable relative order preserved', () => {
|
|
80
|
+
const rows = [
|
|
81
|
+
{ id: 1, score: 10 },
|
|
82
|
+
{ id: 2, score: 10 },
|
|
83
|
+
{ id: 3, score: 10 },
|
|
84
|
+
];
|
|
85
|
+
const result = sortRows(rows, [{ field: 'score', sort: 'asc' }]);
|
|
86
|
+
expect(result.map(r => r.id)).toEqual([1, 2, 3]);
|
|
87
|
+
});
|
|
88
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencorestack/opengridx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "OpenGridX: High-performance React data infrastructure. Unlock advanced Row Grouping, Excel Export, and Column Pinning without the usual \"Pro\" gatekeeping. Built for speed, scale, and complete architectural freedom. Fully open, virtualization-ready, and feature-complete.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/opengridx.umd.js",
|
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"build:lib": "tsc --project tsconfig.build.json && vite build --config vite.config.lib.js && cp lib/styles/opengridx.css.d.ts dist/opengridx.css.d.ts",
|
|
42
42
|
"lint": "eslint .",
|
|
43
43
|
"preview": "vite preview",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"coverage": "vitest run --coverage",
|
|
44
47
|
"prepublishOnly": "npm run build:lib"
|
|
45
48
|
},
|
|
46
49
|
"keywords": [
|
|
@@ -85,6 +88,9 @@
|
|
|
85
88
|
},
|
|
86
89
|
"devDependencies": {
|
|
87
90
|
"@eslint/js": "^9.39.1",
|
|
91
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
92
|
+
"@testing-library/react": "^16.3.2",
|
|
93
|
+
"@testing-library/user-event": "^14.6.1",
|
|
88
94
|
"@types/node": "^25.0.8",
|
|
89
95
|
"@types/react": "^19.2.5",
|
|
90
96
|
"@types/react-dom": "^19.2.3",
|
|
@@ -94,13 +100,14 @@
|
|
|
94
100
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
95
101
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
96
102
|
"globals": "^16.5.0",
|
|
103
|
+
"jsdom": "^29.1.1",
|
|
97
104
|
"react": "^19.2.0",
|
|
98
105
|
"react-dom": "^19.2.0",
|
|
106
|
+
"react-router-dom": "^7.13.1",
|
|
99
107
|
"typescript": "^5.9.3",
|
|
108
|
+
"typescript-eslint": "^8.65.0",
|
|
100
109
|
"vite": "^7.2.4",
|
|
101
110
|
"vite-plugin-dts": "^4.5.4",
|
|
102
|
-
"vitest": "^4.0.18"
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
"dependencies": {}
|
|
111
|
+
"vitest": "^4.0.18"
|
|
112
|
+
}
|
|
106
113
|
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { GridRenderContext } from '../../types';
|
|
3
|
-
|
|
4
|
-
export interface VirtualizationParams {
|
|
5
|
-
scrollTop: number;
|
|
6
|
-
scrollLeft: number;
|
|
7
|
-
viewportHeight: number;
|
|
8
|
-
viewportWidth: number;
|
|
9
|
-
rowHeight: number;
|
|
10
|
-
totalRows: number;
|
|
11
|
-
columnWidths: number[];
|
|
12
|
-
overscan?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface VirtualizationResult {
|
|
16
|
-
renderContext: GridRenderContext;
|
|
17
|
-
offsetTop: number;
|
|
18
|
-
offsetLeft: number;
|
|
19
|
-
totalHeight: number;
|
|
20
|
-
totalWidth: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function calculateVirtualization(params: VirtualizationParams): VirtualizationResult {
|
|
24
|
-
const {
|
|
25
|
-
scrollTop,
|
|
26
|
-
scrollLeft,
|
|
27
|
-
viewportHeight,
|
|
28
|
-
viewportWidth,
|
|
29
|
-
rowHeight,
|
|
30
|
-
totalRows,
|
|
31
|
-
columnWidths,
|
|
32
|
-
overscan = 3
|
|
33
|
-
} = params;
|
|
34
|
-
|
|
35
|
-
const firstVisibleRow = Math.floor(scrollTop / rowHeight);
|
|
36
|
-
const lastVisibleRow = Math.min(
|
|
37
|
-
totalRows - 1,
|
|
38
|
-
Math.ceil((scrollTop + viewportHeight) / rowHeight)
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const firstRowIndex = Math.max(0, firstVisibleRow - overscan);
|
|
42
|
-
const lastRowIndex = Math.min(totalRows - 1, lastVisibleRow + overscan);
|
|
43
|
-
|
|
44
|
-
let accumulatedWidth = 0;
|
|
45
|
-
let firstColumnIndex = 0;
|
|
46
|
-
let lastColumnIndex = columnWidths.length - 1;
|
|
47
|
-
let offsetLeft = 0;
|
|
48
|
-
|
|
49
|
-
for (let i = 0; i < columnWidths.length; i++) {
|
|
50
|
-
if (accumulatedWidth + columnWidths[i] > scrollLeft) {
|
|
51
|
-
firstColumnIndex = Math.max(0, i - overscan);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
accumulatedWidth += columnWidths[i];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
offsetLeft = columnWidths.slice(0, firstColumnIndex).reduce((sum, width) => sum + width, 0);
|
|
58
|
-
|
|
59
|
-
accumulatedWidth = offsetLeft;
|
|
60
|
-
for (let i = firstColumnIndex; i < columnWidths.length; i++) {
|
|
61
|
-
accumulatedWidth += columnWidths[i];
|
|
62
|
-
if (accumulatedWidth >= scrollLeft + viewportWidth) {
|
|
63
|
-
lastColumnIndex = Math.min(columnWidths.length - 1, i + overscan);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const totalHeight = totalRows * rowHeight;
|
|
69
|
-
const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0);
|
|
70
|
-
const offsetTop = firstRowIndex * rowHeight;
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
renderContext: {
|
|
74
|
-
firstRowIndex,
|
|
75
|
-
lastRowIndex,
|
|
76
|
-
firstColumnIndex,
|
|
77
|
-
lastColumnIndex
|
|
78
|
-
},
|
|
79
|
-
offsetTop,
|
|
80
|
-
offsetLeft,
|
|
81
|
-
totalHeight,
|
|
82
|
-
totalWidth
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function getRowPosition(rowIndex: number, rowHeight: number): number {
|
|
87
|
-
return rowIndex * rowHeight;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function getColumnPosition(colIndex: number, columnWidths: number[]): number {
|
|
91
|
-
return columnWidths.slice(0, colIndex).reduce((sum, width) => sum + width, 0);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function isRowVisible(
|
|
95
|
-
rowIndex: number,
|
|
96
|
-
renderContext: GridRenderContext
|
|
97
|
-
): boolean {
|
|
98
|
-
return rowIndex >= renderContext.firstRowIndex && rowIndex <= renderContext.lastRowIndex;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function isColumnVisible(
|
|
102
|
-
colIndex: number,
|
|
103
|
-
renderContext: GridRenderContext
|
|
104
|
-
): boolean {
|
|
105
|
-
return colIndex >= renderContext.firstColumnIndex && colIndex <= renderContext.lastColumnIndex;
|
|
106
|
-
}
|