@azrico/reactgrid 1.2.49 → 1.2.51
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 +30 -3
- package/dist/src/views/DataGrid.js +21 -10
- package/package.json +3 -3
- package/src/example.tsx +35 -26
- package/src/func/func_grid.ts +31 -3
- package/src/views/DataGrid.tsx +24 -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.51](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.51) (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.50](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.50) (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.49](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.2.49) (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,31 @@ 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
|
+
if (rid === -1) return def;
|
|
311
|
+
// console.log('dataSource', alldata);
|
|
312
|
+
return alldata.find(s => get_row_id(s) === rid);
|
|
286
313
|
}
|
|
@@ -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,
|
|
@@ -136,11 +138,12 @@ function DataGridEventsWrapper(props) {
|
|
|
136
138
|
/* ------------------------------- ContextMenu ------------------------------ */
|
|
137
139
|
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
138
140
|
if (!rowProps || !rowProps.data || _func_child.func_selection.has_selection()) return;
|
|
141
|
+
const realRow = (0, _func_grid.find_realData)(rowProps.dataSourceArray, event.target, rowProps.data);
|
|
139
142
|
const anEl = _func_child.func_selection.getVirtualElement(event.clientX, event.clientY);
|
|
140
|
-
update_menuRow(
|
|
143
|
+
update_menuRow(realRow, anEl);
|
|
141
144
|
}, []);
|
|
142
145
|
const update_menuRow = _react.default.useCallback((r = null, el = null) => {
|
|
143
|
-
console.log('Set menuRow:', r);
|
|
146
|
+
// console.log('Set menuRow:', r);
|
|
144
147
|
set_menuRow(r || null);
|
|
145
148
|
set_menuAnchorEl(el || null);
|
|
146
149
|
}, []);
|
|
@@ -152,8 +155,6 @@ function DataGridEventsWrapper(props) {
|
|
|
152
155
|
menuProps.onDismiss();
|
|
153
156
|
update_menuRow();
|
|
154
157
|
}
|
|
155
|
-
console.log('rowProps.data:', rowProps.data);
|
|
156
|
-
console.log('menuRow:', menuRow);
|
|
157
158
|
return _react.default.createElement(_controls.ContextMenu, {
|
|
158
159
|
menuAnchorEl: menuAnchorEl,
|
|
159
160
|
menuRow: menuRow,
|
|
@@ -161,6 +162,12 @@ function DataGridEventsWrapper(props) {
|
|
|
161
162
|
menu_items: props.contextMenuItems
|
|
162
163
|
});
|
|
163
164
|
}, [props.contextMenuItems, menuAnchorEl, menuRow, update_menuRow]);
|
|
165
|
+
/* -------------------------------------------------------------------------- */
|
|
166
|
+
const onRenderRow = (0, _react.useCallback)(rowProps => {
|
|
167
|
+
// save the original handlers to be called later
|
|
168
|
+
rowProps['data-row-id'] = (0, _func_grid.get_row_id)(rowProps.data);
|
|
169
|
+
}, []);
|
|
170
|
+
/* -------------------------------------------------------------------------- */
|
|
164
171
|
/**
|
|
165
172
|
* Merge click events into grid options
|
|
166
173
|
*/
|
|
@@ -172,12 +179,16 @@ function DataGridEventsWrapper(props) {
|
|
|
172
179
|
const contextmenuProps = {
|
|
173
180
|
renderRowContextMenu: renderRowContextMenu
|
|
174
181
|
};
|
|
182
|
+
const renderProps = {
|
|
183
|
+
onRenderRow: onRenderRow
|
|
184
|
+
};
|
|
175
185
|
return {
|
|
176
186
|
...props.static_gridOptions,
|
|
177
187
|
...events,
|
|
178
|
-
...contextmenuProps
|
|
188
|
+
...contextmenuProps,
|
|
189
|
+
...renderProps
|
|
179
190
|
};
|
|
180
|
-
}, [props.static_gridOptions,
|
|
191
|
+
}, [props.static_gridOptions, renderRowContextMenu]);
|
|
181
192
|
/* -------------------------------------------------------------------------- */
|
|
182
193
|
return props.details_dataSource ? _react.default.createElement(DataGridDetailsWrapper, {
|
|
183
194
|
...props,
|
|
@@ -193,7 +204,7 @@ function DataGridDetailsWrapper(props) {
|
|
|
193
204
|
}, [props.details_columns]);
|
|
194
205
|
const cached_data = _react.default.useRef();
|
|
195
206
|
const last_cache_info = _react.default.useRef();
|
|
196
|
-
const
|
|
207
|
+
const details_dataSource = _react.default.useCallback(async dt => {
|
|
197
208
|
const res = await (0, _func_grid.ApplyDataSource)(props.details_dataSource, {
|
|
198
209
|
skip: dt.skip,
|
|
199
210
|
limit: dt.limit,
|
|
@@ -201,13 +212,13 @@ function DataGridDetailsWrapper(props) {
|
|
|
201
212
|
last_cache_info: last_cache_info
|
|
202
213
|
});
|
|
203
214
|
return res;
|
|
204
|
-
}, [props.
|
|
215
|
+
}, [props.details_dataSource]);
|
|
205
216
|
const renderDetailsGrid = ({
|
|
206
217
|
data
|
|
207
218
|
}) => {
|
|
208
219
|
return _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
209
220
|
defaultFilterValue: props.details_filter,
|
|
210
|
-
dataSource:
|
|
221
|
+
dataSource: details_dataSource,
|
|
211
222
|
columns: cached_details_columns
|
|
212
223
|
});
|
|
213
224
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azrico/reactgrid",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.51",
|
|
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,32 @@ 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
|
+
if (rid === -1) return def;
|
|
321
|
+
// console.log('dataSource', alldata);
|
|
322
|
+
return alldata.find((s) => get_row_id(s) === rid);
|
|
323
|
+
}
|
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
|
|
|
@@ -291,12 +292,13 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
291
292
|
/* ------------------------------- ContextMenu ------------------------------ */
|
|
292
293
|
const onRowContextMenu = React.useCallback((rowProps, event) => {
|
|
293
294
|
if (!rowProps || !rowProps.data || func_selection.has_selection()) return;
|
|
295
|
+
const realRow = find_realData(rowProps.dataSourceArray, event.target, rowProps.data);
|
|
294
296
|
const anEl = func_selection.getVirtualElement(event.clientX, event.clientY);
|
|
295
|
-
update_menuRow(
|
|
297
|
+
update_menuRow(realRow, anEl);
|
|
296
298
|
}, []);
|
|
297
299
|
|
|
298
300
|
const update_menuRow = React.useCallback((r: any = null, el: any = null) => {
|
|
299
|
-
console.log('Set menuRow:', r);
|
|
301
|
+
// console.log('Set menuRow:', r);
|
|
300
302
|
set_menuRow(r || null);
|
|
301
303
|
set_menuAnchorEl(el || null);
|
|
302
304
|
}, []);
|
|
@@ -308,8 +310,6 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
308
310
|
menuProps.onDismiss();
|
|
309
311
|
update_menuRow();
|
|
310
312
|
}
|
|
311
|
-
console.log('rowProps.data:', rowProps.data);
|
|
312
|
-
console.log('menuRow:', menuRow);
|
|
313
313
|
|
|
314
314
|
return (
|
|
315
315
|
<ContextMenu
|
|
@@ -322,6 +322,12 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
322
322
|
},
|
|
323
323
|
[props.contextMenuItems, menuAnchorEl, menuRow, update_menuRow]
|
|
324
324
|
);
|
|
325
|
+
/* -------------------------------------------------------------------------- */
|
|
326
|
+
const onRenderRow = useCallback((rowProps) => {
|
|
327
|
+
// save the original handlers to be called later
|
|
328
|
+
rowProps['data-row-id'] = get_row_id(rowProps.data);
|
|
329
|
+
}, []);
|
|
330
|
+
/* -------------------------------------------------------------------------- */
|
|
325
331
|
/**
|
|
326
332
|
* Merge click events into grid options
|
|
327
333
|
*/
|
|
@@ -333,8 +339,16 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
333
339
|
const contextmenuProps: AzGridOptions = {
|
|
334
340
|
renderRowContextMenu: renderRowContextMenu,
|
|
335
341
|
};
|
|
336
|
-
|
|
337
|
-
|
|
342
|
+
const renderProps: any = {
|
|
343
|
+
onRenderRow: onRenderRow,
|
|
344
|
+
};
|
|
345
|
+
return {
|
|
346
|
+
...props.static_gridOptions,
|
|
347
|
+
...events,
|
|
348
|
+
...contextmenuProps,
|
|
349
|
+
...renderProps,
|
|
350
|
+
};
|
|
351
|
+
}, [props.static_gridOptions, renderRowContextMenu]);
|
|
338
352
|
|
|
339
353
|
/* -------------------------------------------------------------------------- */
|
|
340
354
|
|
|
@@ -353,7 +367,7 @@ function DataGridDetailsWrapper(props: DataGridWrapperProps) {
|
|
|
353
367
|
const cached_data = React.useRef<any>();
|
|
354
368
|
const last_cache_info = React.useRef<any>();
|
|
355
369
|
|
|
356
|
-
const
|
|
370
|
+
const details_dataSource = React.useCallback(
|
|
357
371
|
async (dt) => {
|
|
358
372
|
const res = await ApplyDataSource(props.details_dataSource, {
|
|
359
373
|
skip: dt.skip,
|
|
@@ -363,13 +377,13 @@ function DataGridDetailsWrapper(props: DataGridWrapperProps) {
|
|
|
363
377
|
});
|
|
364
378
|
return res;
|
|
365
379
|
},
|
|
366
|
-
[props.
|
|
380
|
+
[props.details_dataSource]
|
|
367
381
|
);
|
|
368
382
|
const renderDetailsGrid = ({ data }) => {
|
|
369
383
|
return (
|
|
370
384
|
<ReactDataGrid
|
|
371
385
|
defaultFilterValue={props.details_filter}
|
|
372
|
-
dataSource={
|
|
386
|
+
dataSource={details_dataSource}
|
|
373
387
|
columns={cached_details_columns}
|
|
374
388
|
></ReactDataGrid>
|
|
375
389
|
);
|