@azrico/reactgrid 1.2.48 → 1.2.50
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 +28 -0
- package/dist/src/example.js +32 -20
- package/dist/src/func/func_grid.d.ts +7 -0
- package/dist/src/func/func_grid.js +31 -3
- package/dist/src/views/DataGrid.js +25 -9
- package/package.json +3 -3
- package/src/example.tsx +35 -26
- package/src/func/func_grid.ts +32 -3
- package/src/views/DataGrid.tsx +30 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.2.50](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.50) (2023-07-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* DataGridDelayedSizeWrapper actual delayed ([2ddfd2f](https://github.com/Azrideus/azrico-reactgrid/commit/2ddfd2fb58c90bd906e1330f22f0ef7468d34afb))
|
|
16
|
+
* onCellSelectionChange ([95c8f54](https://github.com/Azrideus/azrico-reactgrid/commit/95c8f540e94dde0c7e245fb29fb6afc7172957ec))
|
|
17
|
+
* styling ([9018f75](https://github.com/Azrideus/azrico-reactgrid/commit/9018f7593e253720f751f52855a2d956dfc578ed))
|
|
18
|
+
|
|
19
|
+
### [1.2.49](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.49) (2023-07-09)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* DataGridDelayedSizeWrapper actual delayed ([2ddfd2f](https://github.com/Azrideus/azrico-reactgrid/commit/2ddfd2fb58c90bd906e1330f22f0ef7468d34afb))
|
|
30
|
+
* onCellSelectionChange ([95c8f54](https://github.com/Azrideus/azrico-reactgrid/commit/95c8f540e94dde0c7e245fb29fb6afc7172957ec))
|
|
31
|
+
* styling ([9018f75](https://github.com/Azrideus/azrico-reactgrid/commit/9018f7593e253720f751f52855a2d956dfc578ed))
|
|
32
|
+
|
|
5
33
|
### [1.2.48](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.48) (2023-07-09)
|
|
6
34
|
|
|
7
35
|
|
package/dist/src/example.js
CHANGED
|
@@ -40,7 +40,6 @@ const columns = [{
|
|
|
40
40
|
defaultFlex: 1
|
|
41
41
|
}];
|
|
42
42
|
const editableColumns = ['job', 'age'];
|
|
43
|
-
const contextMenuItems = ['test'];
|
|
44
43
|
function getData(delta, max = 200) {
|
|
45
44
|
const fd = [];
|
|
46
45
|
console.log('Delta:', delta);
|
|
@@ -75,22 +74,29 @@ function ExampleGrid() {
|
|
|
75
74
|
const [ds_reset, set_ds_reset] = _react.default.useState(0);
|
|
76
75
|
const [delta, set_delta] = _react.default.useState({});
|
|
77
76
|
const [delayed_reload, set_delayed_reload] = _react.default.useState(false);
|
|
78
|
-
const dataSource = _react.default.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
const dataSource = _react.default.useMemo(() => getData(delta), []);
|
|
78
|
+
// const dataSource = React.useCallback(
|
|
79
|
+
// async (dt) => {
|
|
80
|
+
// //console.log('Start loading');
|
|
81
|
+
// return await new Promise((resolve) => {
|
|
82
|
+
// setTimeout(() => {
|
|
83
|
+
// resolve(getData(delta));
|
|
84
|
+
// }, 1000);
|
|
85
|
+
// });
|
|
86
|
+
// },
|
|
87
|
+
// [ds_reset, delta]
|
|
88
|
+
// );
|
|
89
|
+
// const details_dataSource = React.useCallback(
|
|
90
|
+
// async (dt) => {
|
|
91
|
+
// //console.log('Start loading');
|
|
92
|
+
// return await new Promise((resolve) => {
|
|
93
|
+
// setTimeout(() => {
|
|
94
|
+
// resolve(getData(delta, 5));
|
|
95
|
+
// }, 1000);
|
|
96
|
+
// });
|
|
97
|
+
// },
|
|
98
|
+
// [ds_reset, delta]
|
|
99
|
+
// );
|
|
94
100
|
function onEditComplete(params) {
|
|
95
101
|
const {
|
|
96
102
|
value,
|
|
@@ -126,10 +132,17 @@ function ExampleGrid() {
|
|
|
126
132
|
render: r => r.value + '^'
|
|
127
133
|
}];
|
|
128
134
|
}, [delayed_reload]);
|
|
135
|
+
const contextMenuItems = _react.default.useCallback(product => {
|
|
136
|
+
return [{
|
|
137
|
+
type: 'text',
|
|
138
|
+
content: product.name
|
|
139
|
+
}];
|
|
140
|
+
}, []);
|
|
129
141
|
return _react.default.createElement(_DataGrid.default, {
|
|
130
142
|
dark: true,
|
|
131
143
|
delayedSize: true,
|
|
132
|
-
|
|
144
|
+
// details_dataSource={details_dataSource}
|
|
145
|
+
dataSource: dataSource,
|
|
133
146
|
details_columns: columns,
|
|
134
147
|
onRowClick: onRowClick,
|
|
135
148
|
onRowDoubleClick: onRowDoubleClick,
|
|
@@ -153,8 +166,7 @@ function ExampleGrid() {
|
|
|
153
166
|
// pageSizes: [100],
|
|
154
167
|
// rowIndexColumn: true,
|
|
155
168
|
// checkboxColumn: true,
|
|
156
|
-
}
|
|
157
|
-
dataSource: dataSource
|
|
169
|
+
}
|
|
158
170
|
});
|
|
159
171
|
}
|
|
160
172
|
var _default = ExampleGrid;
|
|
@@ -37,3 +37,10 @@ export declare function set_row_id(obj: any, val: undefined | string): any;
|
|
|
37
37
|
*/
|
|
38
38
|
export declare function get_default_key(): string;
|
|
39
39
|
export declare function validateCache(current: any, old: any, looseCheck?: boolean): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* find the real index of the given row data
|
|
42
|
+
* sometimes when we scroll the rowData prop becomes invalid
|
|
43
|
+
* but we can manually find the correct data by reading the id from clicked item's Html props
|
|
44
|
+
* @param view
|
|
45
|
+
*/
|
|
46
|
+
export declare function find_realData(alldata: any[], view: any, def?: undefined): any;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ApplyColumnData = ApplyColumnData;
|
|
7
7
|
exports.ApplyDataSource = ApplyDataSource;
|
|
8
|
+
exports.find_realData = find_realData;
|
|
8
9
|
exports.get_col_header = get_col_header;
|
|
9
10
|
exports.get_col_name = get_col_name;
|
|
10
11
|
exports.get_default_key = get_default_key;
|
|
@@ -260,9 +261,8 @@ function get_col_header(obj) {
|
|
|
260
261
|
* @returns
|
|
261
262
|
*/
|
|
262
263
|
function get_row_id(obj) {
|
|
263
|
-
if (
|
|
264
|
-
if (typeof obj
|
|
265
|
-
if (typeof obj != 'object') return undefined;
|
|
264
|
+
if (typeof obj === 'string') return obj;
|
|
265
|
+
if (typeof obj !== 'object' || !obj) return undefined;
|
|
266
266
|
return obj.__table_id || obj.id || undefined;
|
|
267
267
|
}
|
|
268
268
|
function set_row_id(obj, val) {
|
|
@@ -283,4 +283,32 @@ function validateCache(current, old, looseCheck = false) {
|
|
|
283
283
|
if (looseCheck) return true;
|
|
284
284
|
if (current.ds != old.ds) return false;
|
|
285
285
|
return true;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* find the real index of the given row data
|
|
289
|
+
* @param view
|
|
290
|
+
*/
|
|
291
|
+
function find_realIndex(view) {
|
|
292
|
+
let current_parent = view;
|
|
293
|
+
for (let index = 0; index < 3; index++) {
|
|
294
|
+
var _current_parent;
|
|
295
|
+
current_parent = current_parent.parentElement;
|
|
296
|
+
const dataId = (_current_parent = current_parent) === null || _current_parent === void 0 ? void 0 : _current_parent.getAttribute('data-row-id');
|
|
297
|
+
if (dataId) return dataId;
|
|
298
|
+
}
|
|
299
|
+
return -1;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* find the real index of the given row data
|
|
303
|
+
* sometimes when we scroll the rowData prop becomes invalid
|
|
304
|
+
* but we can manually find the correct data by reading the id from clicked item's Html props
|
|
305
|
+
* @param view
|
|
306
|
+
*/
|
|
307
|
+
function find_realData(alldata, view, def = undefined) {
|
|
308
|
+
if (!Array.isArray(alldata)) return def;
|
|
309
|
+
const rid = find_realIndex(view);
|
|
310
|
+
console.log('rid:', rid);
|
|
311
|
+
if (rid === -1) return def;
|
|
312
|
+
// console.log('dataSource', alldata);
|
|
313
|
+
return alldata.find(s => get_row_id(s) === rid);
|
|
286
314
|
}
|
|
@@ -12,12 +12,14 @@ require("../themes/base_styles.css");
|
|
|
12
12
|
require("../themes/grid.css");
|
|
13
13
|
var _func_grid = require("../func/func_grid");
|
|
14
14
|
var _controls = require("@azrico/controls");
|
|
15
|
-
var _react =
|
|
15
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
16
16
|
var _func_child = require("../func/func_child");
|
|
17
17
|
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
18
18
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
19
19
|
var _reactUseSize = require("react-use-size");
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
23
|
/* -------------------------------------------------------------------------- */
|
|
22
24
|
const defaultOptions = {
|
|
23
25
|
//filterTypes: defaultfilterTypes,
|
|
@@ -50,6 +52,7 @@ function AzGrid(props) {
|
|
|
50
52
|
/* -------------------------------------------------------------------------- */
|
|
51
53
|
const cached_data = _react.default.useRef();
|
|
52
54
|
const last_cache_info = _react.default.useRef();
|
|
55
|
+
const rawDataSource = props.dataSource;
|
|
53
56
|
const dataSource = _react.default.useCallback(async dt => {
|
|
54
57
|
return await (0, _func_grid.ApplyDataSource)(props.dataSource, {
|
|
55
58
|
skip: dt.skip,
|
|
@@ -102,6 +105,7 @@ function AzGrid(props) {
|
|
|
102
105
|
dynamic_gridOptions: dynamic_gridOptions,
|
|
103
106
|
columns: cached_columns,
|
|
104
107
|
dataSource: dataSource,
|
|
108
|
+
rawDataSource: rawDataSource,
|
|
105
109
|
highlightedRow: props.highlightedRow
|
|
106
110
|
});
|
|
107
111
|
}
|
|
@@ -136,10 +140,12 @@ function DataGridEventsWrapper(props) {
|
|
|
136
140
|
/* ------------------------------- ContextMenu ------------------------------ */
|
|
137
141
|
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
138
142
|
if (!rowProps || !rowProps.data || _func_child.func_selection.has_selection()) return;
|
|
143
|
+
const realRow = (0, _func_grid.find_realData)(props.rawDataSource, event.target, rowProps.data);
|
|
139
144
|
const anEl = _func_child.func_selection.getVirtualElement(event.clientX, event.clientY);
|
|
140
|
-
update_menuRow(
|
|
145
|
+
update_menuRow(realRow, anEl);
|
|
141
146
|
}, []);
|
|
142
|
-
const update_menuRow = _react.default.useCallback((r, el) => {
|
|
147
|
+
const update_menuRow = _react.default.useCallback((r = null, el = null) => {
|
|
148
|
+
// console.log('Set menuRow:', r);
|
|
143
149
|
set_menuRow(r || null);
|
|
144
150
|
set_menuAnchorEl(el || null);
|
|
145
151
|
}, []);
|
|
@@ -149,7 +155,7 @@ function DataGridEventsWrapper(props) {
|
|
|
149
155
|
menuProps.autoDismiss = true;
|
|
150
156
|
function onclose() {
|
|
151
157
|
menuProps.onDismiss();
|
|
152
|
-
|
|
158
|
+
update_menuRow();
|
|
153
159
|
}
|
|
154
160
|
return _react.default.createElement(_controls.ContextMenu, {
|
|
155
161
|
menuAnchorEl: menuAnchorEl,
|
|
@@ -158,6 +164,12 @@ function DataGridEventsWrapper(props) {
|
|
|
158
164
|
menu_items: props.contextMenuItems
|
|
159
165
|
});
|
|
160
166
|
}, [props.contextMenuItems, menuAnchorEl, menuRow, update_menuRow]);
|
|
167
|
+
/* -------------------------------------------------------------------------- */
|
|
168
|
+
const onRenderRow = (0, _react.useCallback)(rowProps => {
|
|
169
|
+
// save the original handlers to be called later
|
|
170
|
+
rowProps['data-row-id'] = (0, _func_grid.get_row_id)(rowProps.data);
|
|
171
|
+
}, []);
|
|
172
|
+
/* -------------------------------------------------------------------------- */
|
|
161
173
|
/**
|
|
162
174
|
* Merge click events into grid options
|
|
163
175
|
*/
|
|
@@ -169,12 +181,16 @@ function DataGridEventsWrapper(props) {
|
|
|
169
181
|
const contextmenuProps = {
|
|
170
182
|
renderRowContextMenu: renderRowContextMenu
|
|
171
183
|
};
|
|
184
|
+
const renderProps = {
|
|
185
|
+
onRenderRow: onRenderRow
|
|
186
|
+
};
|
|
172
187
|
return {
|
|
173
188
|
...props.static_gridOptions,
|
|
174
189
|
...events,
|
|
175
|
-
...contextmenuProps
|
|
190
|
+
...contextmenuProps,
|
|
191
|
+
...renderProps
|
|
176
192
|
};
|
|
177
|
-
}, [props.static_gridOptions,
|
|
193
|
+
}, [props.static_gridOptions, renderRowContextMenu]);
|
|
178
194
|
/* -------------------------------------------------------------------------- */
|
|
179
195
|
return props.details_dataSource ? _react.default.createElement(DataGridDetailsWrapper, {
|
|
180
196
|
...props,
|
|
@@ -190,7 +206,7 @@ function DataGridDetailsWrapper(props) {
|
|
|
190
206
|
}, [props.details_columns]);
|
|
191
207
|
const cached_data = _react.default.useRef();
|
|
192
208
|
const last_cache_info = _react.default.useRef();
|
|
193
|
-
const
|
|
209
|
+
const details_dataSource = _react.default.useCallback(async dt => {
|
|
194
210
|
const res = await (0, _func_grid.ApplyDataSource)(props.details_dataSource, {
|
|
195
211
|
skip: dt.skip,
|
|
196
212
|
limit: dt.limit,
|
|
@@ -198,13 +214,13 @@ function DataGridDetailsWrapper(props) {
|
|
|
198
214
|
last_cache_info: last_cache_info
|
|
199
215
|
});
|
|
200
216
|
return res;
|
|
201
|
-
}, [props.
|
|
217
|
+
}, [props.details_dataSource]);
|
|
202
218
|
const renderDetailsGrid = ({
|
|
203
219
|
data
|
|
204
220
|
}) => {
|
|
205
221
|
return _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
206
222
|
defaultFilterValue: props.details_filter,
|
|
207
|
-
dataSource:
|
|
223
|
+
dataSource: details_dataSource,
|
|
208
224
|
columns: cached_details_columns
|
|
209
225
|
});
|
|
210
226
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azrico/reactgrid",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.50",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "React Datagrid",
|
|
6
6
|
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@azrico/object": "^1.4.35",
|
|
34
34
|
"@emotion/react": "^11.9.3",
|
|
35
35
|
"@emotion/styled": "^11.9.3",
|
|
36
|
-
"@inovua/reactdatagrid-enterprise": "^5.
|
|
36
|
+
"@inovua/reactdatagrid-enterprise": "^5.9.5",
|
|
37
37
|
"clsx": "^1.2.1",
|
|
38
38
|
"react": "^18.2.0",
|
|
39
39
|
"react-use-size": "^3.0.1"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@azrico/object": ">=1.4.12",
|
|
44
44
|
"@emotion/react": ">=11.9.3",
|
|
45
45
|
"@emotion/styled": ">=11.9.3",
|
|
46
|
-
"@inovua/reactdatagrid-enterprise": ">=5.
|
|
46
|
+
"@inovua/reactdatagrid-enterprise": ">=5.9.5",
|
|
47
47
|
"clsx": ">=1.2.1",
|
|
48
48
|
"react": ">=18.2.0",
|
|
49
49
|
"react-use-size": ">=3.0.1"
|
package/src/example.tsx
CHANGED
|
@@ -27,7 +27,6 @@ const columns = [
|
|
|
27
27
|
];
|
|
28
28
|
|
|
29
29
|
const editableColumns = ['job', 'age'];
|
|
30
|
-
const contextMenuItems = ['test'];
|
|
31
30
|
|
|
32
31
|
function getData(delta: any, max = 200) {
|
|
33
32
|
const fd: any[] = [];
|
|
@@ -67,28 +66,29 @@ export function ExampleGrid() {
|
|
|
67
66
|
const [delta, set_delta] = React.useState({});
|
|
68
67
|
const [delayed_reload, set_delayed_reload] = React.useState(false);
|
|
69
68
|
|
|
70
|
-
const dataSource = React.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
const dataSource = React.useMemo(() => getData(delta), []);
|
|
70
|
+
// const dataSource = React.useCallback(
|
|
71
|
+
// async (dt) => {
|
|
72
|
+
// //console.log('Start loading');
|
|
73
|
+
// return await new Promise((resolve) => {
|
|
74
|
+
// setTimeout(() => {
|
|
75
|
+
// resolve(getData(delta));
|
|
76
|
+
// }, 1000);
|
|
77
|
+
// });
|
|
78
|
+
// },
|
|
79
|
+
// [ds_reset, delta]
|
|
80
|
+
// );
|
|
81
|
+
// const details_dataSource = React.useCallback(
|
|
82
|
+
// async (dt) => {
|
|
83
|
+
// //console.log('Start loading');
|
|
84
|
+
// return await new Promise((resolve) => {
|
|
85
|
+
// setTimeout(() => {
|
|
86
|
+
// resolve(getData(delta, 5));
|
|
87
|
+
// }, 1000);
|
|
88
|
+
// });
|
|
89
|
+
// },
|
|
90
|
+
// [ds_reset, delta]
|
|
91
|
+
// );
|
|
92
92
|
|
|
93
93
|
function onEditComplete(params) {
|
|
94
94
|
const { value, columnId, rowId, ...rest } = params;
|
|
@@ -117,18 +117,28 @@ export function ExampleGrid() {
|
|
|
117
117
|
return [{ name: 'name', render: (r) => r.value + '^' }];
|
|
118
118
|
}, [delayed_reload]);
|
|
119
119
|
|
|
120
|
+
const contextMenuItems = React.useCallback((product: any) => {
|
|
121
|
+
return [
|
|
122
|
+
{
|
|
123
|
+
type: 'text',
|
|
124
|
+
content: product.name,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
120
129
|
return (
|
|
121
130
|
<AzGrid
|
|
122
131
|
dark
|
|
123
132
|
delayedSize
|
|
124
|
-
details_dataSource={details_dataSource}
|
|
133
|
+
// details_dataSource={details_dataSource}
|
|
134
|
+
dataSource={dataSource}
|
|
125
135
|
details_columns={columns}
|
|
126
136
|
onRowClick={onRowClick}
|
|
127
137
|
onRowDoubleClick={onRowDoubleClick}
|
|
128
138
|
allowChildRows
|
|
129
139
|
// onSelectionChange={onSelectionChange}
|
|
130
140
|
// selected={selected}
|
|
131
|
-
contextMenuItems={contextMenuItems}
|
|
141
|
+
contextMenuItems={contextMenuItems as any}
|
|
132
142
|
customColumns={customColumns}
|
|
133
143
|
columns={columns}
|
|
134
144
|
editableColumns={editableColumns}
|
|
@@ -148,7 +158,6 @@ export function ExampleGrid() {
|
|
|
148
158
|
// checkboxColumn: true,
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
|
-
dataSource={dataSource}
|
|
152
161
|
/>
|
|
153
162
|
);
|
|
154
163
|
}
|
package/src/func/func_grid.ts
CHANGED
|
@@ -264,9 +264,8 @@ export function get_col_header(obj: any): string {
|
|
|
264
264
|
* @returns
|
|
265
265
|
*/
|
|
266
266
|
export function get_row_id(obj: any): any {
|
|
267
|
-
if (
|
|
268
|
-
if (typeof obj
|
|
269
|
-
if (typeof obj != 'object') return undefined;
|
|
267
|
+
if (typeof obj === 'string') return obj;
|
|
268
|
+
if (typeof obj !== 'object' || !obj) return undefined;
|
|
270
269
|
return obj.__table_id || obj.id || undefined;
|
|
271
270
|
}
|
|
272
271
|
export function set_row_id(obj: any, val: undefined | string): any {
|
|
@@ -293,3 +292,33 @@ export function validateCache(current: any, old: any, looseCheck = false) {
|
|
|
293
292
|
if (current.ds != old.ds) return false;
|
|
294
293
|
return true;
|
|
295
294
|
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* find the real index of the given row data
|
|
298
|
+
* @param view
|
|
299
|
+
*/
|
|
300
|
+
function find_realIndex(view) {
|
|
301
|
+
let current_parent = view;
|
|
302
|
+
|
|
303
|
+
for (let index = 0; index < 3; index++) {
|
|
304
|
+
current_parent = current_parent.parentElement;
|
|
305
|
+
const dataId = current_parent?.getAttribute('data-row-id');
|
|
306
|
+
if (dataId) return dataId;
|
|
307
|
+
}
|
|
308
|
+
return -1;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* find the real index of the given row data
|
|
313
|
+
* sometimes when we scroll the rowData prop becomes invalid
|
|
314
|
+
* but we can manually find the correct data by reading the id from clicked item's Html props
|
|
315
|
+
* @param view
|
|
316
|
+
*/
|
|
317
|
+
export function find_realData(alldata: any[], view, def = undefined) {
|
|
318
|
+
if (!Array.isArray(alldata)) return def;
|
|
319
|
+
const rid = find_realIndex(view);
|
|
320
|
+
console.log('rid:', rid);
|
|
321
|
+
if (rid === -1) return def;
|
|
322
|
+
// console.log('dataSource', alldata);
|
|
323
|
+
return alldata.find((s) => get_row_id(s) === rid);
|
|
324
|
+
}
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ApplyColumnData,
|
|
9
9
|
ApplyDataSource,
|
|
10
10
|
ModifyFields,
|
|
11
|
+
find_realData,
|
|
11
12
|
get_default_key,
|
|
12
13
|
get_row_id,
|
|
13
14
|
validateCache,
|
|
@@ -73,7 +74,7 @@ export type AzGridOptions = Partial<TypeDataGridProps>;
|
|
|
73
74
|
/* -------------------------------------------------------------------------- */
|
|
74
75
|
export type AzGridProps = {
|
|
75
76
|
dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
76
|
-
details_dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
77
|
+
details_dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>); //details is rendered under each row
|
|
77
78
|
details_columns?: LooseColumnDefinition[];
|
|
78
79
|
details_filter?: FilterValues;
|
|
79
80
|
|
|
@@ -180,6 +181,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
180
181
|
const cached_data = React.useRef<any>();
|
|
181
182
|
const last_cache_info = React.useRef<any>();
|
|
182
183
|
|
|
184
|
+
const rawDataSource = props.dataSource;
|
|
183
185
|
const dataSource = React.useCallback(
|
|
184
186
|
async (dt) => {
|
|
185
187
|
return await ApplyDataSource(props.dataSource, {
|
|
@@ -242,6 +244,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
242
244
|
dynamic_gridOptions={dynamic_gridOptions}
|
|
243
245
|
columns={cached_columns}
|
|
244
246
|
dataSource={dataSource}
|
|
247
|
+
rawDataSource={rawDataSource}
|
|
245
248
|
highlightedRow={props.highlightedRow}
|
|
246
249
|
/>
|
|
247
250
|
);
|
|
@@ -253,7 +256,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
253
256
|
* @param props
|
|
254
257
|
* @returns
|
|
255
258
|
*/
|
|
256
|
-
function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
259
|
+
function DataGridEventsWrapper(props: DataGridWrapperProps & { rawDataSource: any }) {
|
|
257
260
|
/* -------------------------------------------------------------------------- */
|
|
258
261
|
|
|
259
262
|
const click_data = React.useRef<any>(null);
|
|
@@ -291,11 +294,13 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
291
294
|
/* ------------------------------- ContextMenu ------------------------------ */
|
|
292
295
|
const onRowContextMenu = React.useCallback((rowProps, event) => {
|
|
293
296
|
if (!rowProps || !rowProps.data || func_selection.has_selection()) return;
|
|
297
|
+
const realRow = find_realData(props.rawDataSource, event.target, rowProps.data);
|
|
294
298
|
const anEl = func_selection.getVirtualElement(event.clientX, event.clientY);
|
|
295
|
-
update_menuRow(
|
|
299
|
+
update_menuRow(realRow, anEl);
|
|
296
300
|
}, []);
|
|
297
301
|
|
|
298
|
-
const update_menuRow = React.useCallback((r, el) => {
|
|
302
|
+
const update_menuRow = React.useCallback((r: any = null, el: any = null) => {
|
|
303
|
+
// console.log('Set menuRow:', r);
|
|
299
304
|
set_menuRow(r || null);
|
|
300
305
|
set_menuAnchorEl(el || null);
|
|
301
306
|
}, []);
|
|
@@ -305,8 +310,9 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
305
310
|
menuProps.autoDismiss = true;
|
|
306
311
|
function onclose() {
|
|
307
312
|
menuProps.onDismiss();
|
|
308
|
-
|
|
313
|
+
update_menuRow();
|
|
309
314
|
}
|
|
315
|
+
|
|
310
316
|
return (
|
|
311
317
|
<ContextMenu
|
|
312
318
|
menuAnchorEl={menuAnchorEl}
|
|
@@ -318,6 +324,12 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
318
324
|
},
|
|
319
325
|
[props.contextMenuItems, menuAnchorEl, menuRow, update_menuRow]
|
|
320
326
|
);
|
|
327
|
+
/* -------------------------------------------------------------------------- */
|
|
328
|
+
const onRenderRow = useCallback((rowProps) => {
|
|
329
|
+
// save the original handlers to be called later
|
|
330
|
+
rowProps['data-row-id'] = get_row_id(rowProps.data);
|
|
331
|
+
}, []);
|
|
332
|
+
/* -------------------------------------------------------------------------- */
|
|
321
333
|
/**
|
|
322
334
|
* Merge click events into grid options
|
|
323
335
|
*/
|
|
@@ -329,8 +341,16 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
329
341
|
const contextmenuProps: AzGridOptions = {
|
|
330
342
|
renderRowContextMenu: renderRowContextMenu,
|
|
331
343
|
};
|
|
332
|
-
|
|
333
|
-
|
|
344
|
+
const renderProps: any = {
|
|
345
|
+
onRenderRow: onRenderRow,
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
...props.static_gridOptions,
|
|
349
|
+
...events,
|
|
350
|
+
...contextmenuProps,
|
|
351
|
+
...renderProps,
|
|
352
|
+
};
|
|
353
|
+
}, [props.static_gridOptions, renderRowContextMenu]);
|
|
334
354
|
|
|
335
355
|
/* -------------------------------------------------------------------------- */
|
|
336
356
|
|
|
@@ -349,7 +369,7 @@ function DataGridDetailsWrapper(props: DataGridWrapperProps) {
|
|
|
349
369
|
const cached_data = React.useRef<any>();
|
|
350
370
|
const last_cache_info = React.useRef<any>();
|
|
351
371
|
|
|
352
|
-
const
|
|
372
|
+
const details_dataSource = React.useCallback(
|
|
353
373
|
async (dt) => {
|
|
354
374
|
const res = await ApplyDataSource(props.details_dataSource, {
|
|
355
375
|
skip: dt.skip,
|
|
@@ -359,13 +379,13 @@ function DataGridDetailsWrapper(props: DataGridWrapperProps) {
|
|
|
359
379
|
});
|
|
360
380
|
return res;
|
|
361
381
|
},
|
|
362
|
-
[props.
|
|
382
|
+
[props.details_dataSource]
|
|
363
383
|
);
|
|
364
384
|
const renderDetailsGrid = ({ data }) => {
|
|
365
385
|
return (
|
|
366
386
|
<ReactDataGrid
|
|
367
387
|
defaultFilterValue={props.details_filter}
|
|
368
|
-
dataSource={
|
|
388
|
+
dataSource={details_dataSource}
|
|
369
389
|
columns={cached_details_columns}
|
|
370
390
|
></ReactDataGrid>
|
|
371
391
|
);
|