@azrico/reactgrid 1.1.26 → 1.1.28

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.
@@ -32,31 +32,31 @@ const columns = [{
32
32
  name: 'job',
33
33
  title: 'Job',
34
34
  type: 'combo',
35
- items: ['Engineer', 'Doctor'],
35
+ items: ['None', 'Engineer', 'Doctor'],
36
+ defaultFlex: 1
37
+ }, {
38
+ name: 'age',
39
+ title: 'Age',
36
40
  defaultFlex: 1
37
41
  }];
38
- const leftColumns = ['username', 'row'];
39
- const customColumns = [{
40
- name: 'job',
41
- render: () => {
42
- return _react.default.createElement("div", null, "test");
43
- }
44
- }];
45
- const filterValue = [{
46
- name: 'name',
47
- operator: 'contains',
48
- type: 'string',
49
- value: ''
50
- }];
42
+ const editableColumns = ['job', 'age'];
51
43
  const contextMenuItems = ['test'];
52
- function getData() {
44
+ function getData(delta) {
53
45
  const fd = [];
46
+ console.log('Delta:', delta);
54
47
  for (let index = 0; index < 200; index++) {
55
- fd.push({
48
+ const currentObject = {
56
49
  __table_id: String(index),
57
50
  name: 'user-' + index,
58
- age: 20
59
- });
51
+ age: 20,
52
+ job: 'None'
53
+ };
54
+ if (delta[index] && typeof delta[index] === 'object') {
55
+ for (const key in delta[index]) {
56
+ currentObject[key] = delta[index][key];
57
+ }
58
+ }
59
+ fd.push(currentObject);
60
60
  //if (index % 5 == 0) {
61
61
  // const sub_selfid = 's' + index;
62
62
  // fd.push({
@@ -81,15 +81,32 @@ function getData() {
81
81
  }
82
82
  function ExampleGrid() {
83
83
  const [ds_reset, set_ds_reset] = _react.default.useState(0);
84
+ const [delta, set_delta] = _react.default.useState({});
84
85
  const dataSource = _react.default.useCallback(async dt => {
85
86
  //console.log('Start loading');
86
87
  return await new Promise(resolve => {
87
88
  setTimeout(() => {
88
- //console.log('end loading');
89
- resolve(getData());
89
+ resolve(getData(delta));
90
90
  }, 1000);
91
91
  });
92
- }, [ds_reset]);
92
+ }, [ds_reset, delta]);
93
+ function onEditComplete(params) {
94
+ const {
95
+ value,
96
+ columnId,
97
+ rowId,
98
+ ...rest
99
+ } = params;
100
+ let new_rd = delta[rowId];
101
+ if (!new_rd) new_rd = {};
102
+ new_rd[columnId] = value;
103
+ set_delta(d => {
104
+ return {
105
+ ...d,
106
+ [rowId]: new_rd
107
+ };
108
+ });
109
+ }
93
110
  const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
94
111
  console.log((rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
95
112
  }, []);
@@ -102,6 +119,7 @@ function ExampleGrid() {
102
119
  }
103
120
  return _react.default.createElement(_DataGrid.default, {
104
121
  dark: true,
122
+ delayedSize: true,
105
123
  onRowClick: onRowClick,
106
124
  onRowDoubleClick: onRowDoubleClick,
107
125
  // allowChildRows
@@ -110,7 +128,9 @@ function ExampleGrid() {
110
128
  contextMenuItems: contextMenuItems,
111
129
  // customColumns={customColumns}
112
130
  columns: columns,
131
+ editableColumns: editableColumns,
113
132
  editable: true,
133
+ onEditComplete: onEditComplete,
114
134
  // leftColumns={leftColumns}
115
135
  gridOptions: {
116
136
  // defaultFilterValue: filterValue,
@@ -24,3 +24,7 @@
24
24
  .azgrid-nomargin {
25
25
  margin: 0;
26
26
  }
27
+ .azgrid-delayedresize {
28
+ transition-property: 'width,height';
29
+ transition-delay: 200ms;
30
+ }
@@ -59,6 +59,7 @@ export type AzGridProps = {
59
59
  loading?: boolean;
60
60
  dark?: boolean;
61
61
  editable?: boolean;
62
+ delayedSize?: boolean;
62
63
  allowChildRows?: boolean;
63
64
  looseCacheCheck?: boolean;
64
65
  className?: string;
@@ -19,6 +19,7 @@ var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdata
19
19
  var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
20
20
  var _clsx = _interopRequireDefault(require("clsx"));
21
21
  var _object = require("@azrico/object");
22
+ var _reactUseSize = require("react-use-size");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24
  /* -------------------------------------------------------------------------- */
24
25
  // const defaultfilterTypes: FilterTypes = {
@@ -109,29 +110,63 @@ function AzGrid(props) {
109
110
  cached_data.current = result_data;
110
111
  return result_data;
111
112
  }, [props.dataSource]);
112
- return _react.default.createElement(DataGrid, {
113
+ const base_gridOptions = _react.default.useMemo(() => {
114
+ const firstcolumn = cached_columns[0];
115
+ const licenseKey = props.licenseKey || get_default_key();
116
+ const events = {
117
+ onSkipChange: props.onSkipChange,
118
+ onLimitChange: props.onLimitChange,
119
+ onEditComplete: props.onEditComplete
120
+ };
121
+ const extra_ops = {
122
+ onSelectionChange: props.onSelectionChange,
123
+ licenseKey: licenseKey,
124
+ editable: props.editable,
125
+ treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
126
+ renderRowDetails: props.RowDetail,
127
+ theme: props.dark ? 'amber-dark' : 'default-light'
128
+ };
129
+ return {
130
+ ...defaultOptions,
131
+ ...events,
132
+ ...extra_ops
133
+ };
134
+ }, [cached_columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
135
+ const static_gridOptions = _react.default.useMemo(() => {
136
+ return {
137
+ ...base_gridOptions,
138
+ ...props.gridOptions,
139
+ ...forcedOptions
140
+ };
141
+ }, [props.gridOptions, base_gridOptions, forcedOptions]);
142
+ const dynamic_gridOptions = _react.default.useMemo(() => {
143
+ const res = {};
144
+ dynamic_option_names.map(r => {
145
+ res[r] = props[r];
146
+ });
147
+ return res;
148
+ }, dynamic_option_names.map(r => props[r]));
149
+ return _react.default.createElement(DataGridEventsWrapper, {
113
150
  ...props,
151
+ base_gridOptions: base_gridOptions,
152
+ static_gridOptions: static_gridOptions,
153
+ dynamic_gridOptions: dynamic_gridOptions,
114
154
  columns: cached_columns,
115
155
  dataSource: dataSource,
116
156
  highlightedRow: props.highlightedRow
117
157
  });
118
158
  }
119
159
  /* -------------------------------------------------------------------------- */
120
- function DataGrid(props) {
121
- const {
122
- columns,
123
- dataSource,
124
- dark,
125
- contextMenuItems
126
- } = props;
160
+ /**
161
+ * Wrapper for menu events
162
+ * @param props
163
+ * @returns
164
+ */
165
+ function DataGridEventsWrapper(props) {
127
166
  /* -------------------------------------------------------------------------- */
128
- const gridRef = _react.default.useRef(null);
129
167
  const click_data = _react.default.useRef(null);
130
168
  const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
131
169
  const [menuRow, set_menuRow] = _react.default.useState(null);
132
- _react.default.useEffect(() => {
133
- click_data.current = {};
134
- }, [dataSource]);
135
170
  /* --------------------------------- events --------------------------------- */
136
171
  const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
137
172
  if (_helpers.func_selection.has_selection()) return;
@@ -152,6 +187,9 @@ function DataGrid(props) {
152
187
  click_data.current[get_row_id(rowProps)] = nowDate;
153
188
  return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
154
189
  }, []);
190
+ _react.default.useEffect(() => {
191
+ click_data.current = {};
192
+ }, [props.dataSource]);
155
193
  /* ------------------------------- ContextMenu ------------------------------ */
156
194
  const update_menuAnchorEl = _react.default.useCallback(el => {
157
195
  if (el) {
@@ -163,63 +201,72 @@ function DataGrid(props) {
163
201
  set_menuRow(r);
164
202
  } else set_menuRow(null);
165
203
  }, []);
166
- /* -------------------------------------------------------------------------- */
167
- /* Create the grid */
168
- /* -------------------------------------------------------------------------- */
169
204
  const base_gridOptions = _react.default.useMemo(() => {
170
- const firstcolumn = columns[0];
171
- const licenseKey = props.licenseKey || get_default_key();
172
205
  const events = {
173
206
  onRowClick: onRowClick,
174
- onRowContextMenu: onRowContextMenu,
175
- onSkipChange: props.onSkipChange,
176
- onLimitChange: props.onLimitChange,
177
- onEditComplete: props.onEditComplete
178
- };
179
- const extra_ops = {
180
- onSelectionChange: props.onSelectionChange,
181
- licenseKey: licenseKey,
182
- editable: props.editable,
183
- treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
184
- renderRowDetails: props.RowDetail,
185
- theme: dark ? 'amber-dark' : 'default-light'
207
+ onRowContextMenu: onRowContextMenu
186
208
  };
187
209
  return {
188
- ...defaultOptions,
189
- ...events,
190
- ...extra_ops
210
+ ...props.base_gridOptions,
211
+ ...events
191
212
  };
192
- }, [columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
193
- const static_gridOptions = _react.default.useMemo(() => {
194
- return {
195
- ...base_gridOptions,
196
- ...props.gridOptions,
197
- ...forcedOptions
198
- };
199
- }, [props.gridOptions, base_gridOptions, forcedOptions]);
200
- const dynamic_gridOptions = _react.default.useMemo(() => {
201
- const res = {};
202
- dynamic_option_names.map(r => {
203
- res[r] = props[r];
213
+ }, [props.base_gridOptions]);
214
+ return _react.default.createElement(DataGridSizeWrapper, {
215
+ ...props,
216
+ base_gridOptions: base_gridOptions
217
+ }, _react.default.createElement(_controls.ContextMenu, {
218
+ menuAnchorEl: menuAnchorEl,
219
+ set_menuAnchorEl: update_menuAnchorEl,
220
+ menuRow: menuRow,
221
+ items: props.contextMenuItems
222
+ }), props.children);
223
+ }
224
+ function DataGridSizeWrapper(props) {
225
+ if (props.delayedSize) {
226
+ return _react.default.createElement(DataGridDelayedSize, {
227
+ ...props
204
228
  });
205
- return res;
206
- }, dynamic_option_names.map(r => props[r]));
207
- // const { width, height, ref: resize_ref } = useResizeDetector();
229
+ } else {
230
+ return _react.default.createElement(DataGridFlexSize, {
231
+ ...props
232
+ });
233
+ }
234
+ }
235
+ function DataGridDelayedSize(props) {
236
+ const gridRef = _react.default.useRef(null);
237
+ const {
238
+ ref,
239
+ height,
240
+ width
241
+ } = (0, _reactUseSize.useComponentSize)();
208
242
  return _react.default.createElement("div", {
243
+ ref: ref,
209
244
  className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
210
245
  }, _react.default.createElement(_reactdatagridEnterprise.default, {
211
- ...static_gridOptions,
212
- ...dynamic_gridOptions,
246
+ ...props.static_gridOptions,
247
+ ...props.dynamic_gridOptions,
248
+ handle: ref => gridRef.current = ref ? ref.current : null,
249
+ className: 'azgrid-delayedresize',
250
+ style: {
251
+ height: height,
252
+ width: width
253
+ },
254
+ columns: props.columns,
255
+ dataSource: props.dataSource
256
+ }), props.children);
257
+ }
258
+ function DataGridFlexSize(props) {
259
+ const gridRef = _react.default.useRef(null);
260
+ return _react.default.createElement("div", {
261
+ className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
262
+ }, _react.default.createElement(_reactdatagridEnterprise.default, {
263
+ ...props.static_gridOptions,
264
+ ...props.dynamic_gridOptions,
213
265
  handle: ref => gridRef.current = ref ? ref.current : null,
214
266
  className: 'azgrid-filler',
215
- columns: columns,
216
- dataSource: dataSource
217
- }), _react.default.createElement(_controls.ContextMenu, {
218
- menuAnchorEl: menuAnchorEl,
219
- set_menuAnchorEl: update_menuAnchorEl,
220
- menuRow: menuRow,
221
- items: contextMenuItems
222
- }));
267
+ columns: props.columns,
268
+ dataSource: props.dataSource
269
+ }), props.children);
223
270
  }
224
271
  /* -------------------------------------------------------------------------- */
225
272
  /* -------------------------------------------------------------------------- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -36,7 +36,7 @@
36
36
  "@inovua/reactdatagrid-enterprise": "^5.8.1",
37
37
  "clsx": "^1.2.1",
38
38
  "react": "^18.2.0",
39
- "react-resize-detector": "^7.1.2"
39
+ "react-use-size": "^3.0.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@azrico/controls": "*",
@@ -45,7 +45,7 @@
45
45
  "@inovua/reactdatagrid-enterprise": "*",
46
46
  "clsx": "*",
47
47
  "react": "*",
48
- "react-resize-detector": "*"
48
+ "react-use-size": "*"
49
49
  },
50
50
  "browserslist": {
51
51
  "production": [
package/src/example.tsx CHANGED
@@ -4,6 +4,7 @@ import AzGrid from './views/DataGrid';
4
4
  import { LooseColumnDefinition } from './views/DataGrid';
5
5
  import React from 'react';
6
6
  import ReactDOM from 'react-dom/client';
7
+ import { getFormControlUtilityClasses } from '@mui/material';
7
8
 
8
9
  const columns = [
9
10
  {
@@ -15,33 +16,36 @@ const columns = [
15
16
  name: 'job',
16
17
  title: 'Job',
17
18
  type: 'combo',
18
- items: ['Engineer', 'Doctor'],
19
+ items: ['None', 'Engineer', 'Doctor'],
19
20
  defaultFlex: 1,
20
21
  },
21
- ];
22
- const leftColumns = ['username', 'row'];
23
- const customColumns = [
24
22
  {
25
- name: 'job',
26
- render: () => {
27
- return <div>test</div>;
28
- },
29
- },
30
- ];
31
- const filterValue = [
32
- {
33
- name: 'name',
34
- operator: 'contains',
35
- type: 'string',
36
- value: '',
23
+ name: 'age',
24
+ title: 'Age',
25
+ defaultFlex: 1,
37
26
  },
38
27
  ];
39
28
 
29
+ const editableColumns = ['job', 'age'];
40
30
  const contextMenuItems = ['test'];
41
- function getData() {
31
+
32
+ function getData(delta: any) {
42
33
  const fd: any[] = [];
34
+ console.log('Delta:', delta);
43
35
  for (let index = 0; index < 200; index++) {
44
- fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
36
+ const currentObject = {
37
+ __table_id: String(index),
38
+ name: 'user-' + index,
39
+ age: 20,
40
+ job: 'None',
41
+ };
42
+ if (delta[index] && typeof delta[index] === 'object') {
43
+ for (const key in delta[index]) {
44
+ currentObject[key] = delta[index][key];
45
+ }
46
+ }
47
+
48
+ fd.push(currentObject);
45
49
  //if (index % 5 == 0) {
46
50
  // const sub_selfid = 's' + index;
47
51
  // fd.push({
@@ -66,20 +70,30 @@ function getData() {
66
70
 
67
71
  export function ExampleGrid() {
68
72
  const [ds_reset, set_ds_reset] = React.useState(0);
73
+ const [delta, set_delta] = React.useState({});
69
74
 
70
75
  const dataSource = React.useCallback(
71
76
  async (dt) => {
72
77
  //console.log('Start loading');
73
78
  return await new Promise((resolve) => {
74
79
  setTimeout(() => {
75
- //console.log('end loading');
76
- resolve(getData());
80
+ resolve(getData(delta));
77
81
  }, 1000);
78
82
  });
79
83
  },
80
- [ds_reset]
84
+ [ds_reset, delta]
81
85
  );
82
86
 
87
+ function onEditComplete(params) {
88
+ const { value, columnId, rowId, ...rest } = params;
89
+ let new_rd = delta[rowId];
90
+ if (!new_rd) new_rd = {};
91
+ new_rd[columnId] = value;
92
+ set_delta((d) => {
93
+ return { ...d, [rowId]: new_rd };
94
+ });
95
+ }
96
+
83
97
  const onRowDoubleClick = React.useCallback((index: number, rowdata: any) => {
84
98
  console.log(rowdata?.data || rowdata);
85
99
  }, []);
@@ -95,6 +109,7 @@ export function ExampleGrid() {
95
109
  return (
96
110
  <AzGrid
97
111
  dark
112
+ delayedSize
98
113
  onRowClick={onRowClick}
99
114
  onRowDoubleClick={onRowDoubleClick}
100
115
  // allowChildRows
@@ -103,7 +118,9 @@ export function ExampleGrid() {
103
118
  contextMenuItems={contextMenuItems}
104
119
  // customColumns={customColumns}
105
120
  columns={columns}
121
+ editableColumns={editableColumns}
106
122
  editable={true}
123
+ onEditComplete={onEditComplete}
107
124
  // leftColumns={leftColumns}
108
125
  gridOptions={
109
126
  {
@@ -24,3 +24,7 @@
24
24
  .azgrid-nomargin {
25
25
  margin: 0;
26
26
  }
27
+ .azgrid-delayedresize {
28
+ transition-property: 'width,height';
29
+ transition-delay: 200ms;
30
+ }
@@ -25,7 +25,7 @@ import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
25
25
  import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
26
26
  import clsx from 'clsx';
27
27
  import { object_equals } from '@azrico/object';
28
- import { useResizeDetector } from 'react-resize-detector';
28
+ import { useComponentSize } from 'react-use-size';
29
29
 
30
30
  /* -------------------------------------------------------------------------- */
31
31
  type ModifyFields<T, R> = Omit<T, keyof R> & R;
@@ -100,6 +100,7 @@ export type AzGridProps = {
100
100
  loading?: boolean;
101
101
  dark?: boolean;
102
102
  editable?: boolean;
103
+ delayedSize?: boolean;
103
104
  allowChildRows?: boolean;
104
105
  looseCacheCheck?: boolean;
105
106
  className?: string;
@@ -112,6 +113,15 @@ type DataGridProps = ModifyFields<
112
113
  dataSource: any;
113
114
  }
114
115
  >;
116
+ type DataGridWrapperProps = ModifyFields<
117
+ DataGridProps,
118
+ {
119
+ base_gridOptions: GridOptions;
120
+ dynamic_gridOptions: GridOptions;
121
+ static_gridOptions: GridOptions;
122
+ children?: React.ReactNode;
123
+ }
124
+ >;
115
125
  /* -------------------------------------------------------------------------- */
116
126
  // const defaultfilterTypes: FilterTypes = {
117
127
  // string: {
@@ -220,9 +230,52 @@ export function AzGrid(props: AzGridProps) {
220
230
  [props.dataSource]
221
231
  );
222
232
 
233
+ const base_gridOptions = React.useMemo<GridOptions>(() => {
234
+ const firstcolumn = cached_columns[0];
235
+ const licenseKey = props.licenseKey || get_default_key();
236
+ const events: GridOptions = {
237
+ onSkipChange: props.onSkipChange,
238
+ onLimitChange: props.onLimitChange,
239
+ onEditComplete: props.onEditComplete,
240
+ };
241
+ const extra_ops: GridOptions = {
242
+ onSelectionChange: props.onSelectionChange,
243
+ licenseKey: licenseKey,
244
+ editable: props.editable,
245
+ treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
246
+ renderRowDetails: props.RowDetail,
247
+ theme: props.dark ? 'amber-dark' : 'default-light',
248
+ };
249
+ return { ...defaultOptions, ...events, ...extra_ops };
250
+ }, [
251
+ cached_columns,
252
+ props.allowChildRows,
253
+ props.editable,
254
+ props.RowDetail,
255
+ props.onEditComplete,
256
+ ]);
257
+
258
+ const static_gridOptions = React.useMemo<GridOptions>(() => {
259
+ return { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
260
+ }, [props.gridOptions, base_gridOptions, forcedOptions]);
261
+
262
+ const dynamic_gridOptions = React.useMemo<GridOptions>(
263
+ () => {
264
+ const res = {};
265
+ dynamic_option_names.map((r) => {
266
+ res[r] = props[r];
267
+ });
268
+ return res;
269
+ },
270
+ dynamic_option_names.map((r) => props[r])
271
+ );
272
+
223
273
  return (
224
- <DataGrid
274
+ <DataGridEventsWrapper
225
275
  {...props}
276
+ base_gridOptions={base_gridOptions}
277
+ static_gridOptions={static_gridOptions}
278
+ dynamic_gridOptions={dynamic_gridOptions}
226
279
  columns={cached_columns}
227
280
  dataSource={dataSource}
228
281
  highlightedRow={props.highlightedRow}
@@ -231,20 +284,19 @@ export function AzGrid(props: AzGridProps) {
231
284
  }
232
285
 
233
286
  /* -------------------------------------------------------------------------- */
234
- function DataGrid(props: DataGridProps) {
235
- const { columns, dataSource, dark, contextMenuItems } = props;
236
-
287
+ /**
288
+ * Wrapper for menu events
289
+ * @param props
290
+ * @returns
291
+ */
292
+ function DataGridEventsWrapper(props: DataGridWrapperProps) {
237
293
  /* -------------------------------------------------------------------------- */
238
- const gridRef = React.useRef<any>(null);
294
+
239
295
  const click_data = React.useRef<any>(null);
240
296
 
241
297
  const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
242
298
  const [menuRow, set_menuRow] = React.useState<any>(null);
243
299
 
244
- React.useEffect(() => {
245
- click_data.current = {};
246
- }, [dataSource]);
247
-
248
300
  /* --------------------------------- events --------------------------------- */
249
301
 
250
302
  const onRowContextMenu = React.useCallback((rowProps, event) => {
@@ -270,6 +322,11 @@ function DataGrid(props: DataGridProps) {
270
322
  click_data.current[get_row_id(rowProps)] = nowDate;
271
323
  return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
272
324
  }, []);
325
+
326
+ React.useEffect(() => {
327
+ click_data.current = {};
328
+ }, [props.dataSource]);
329
+
273
330
  /* ------------------------------- ContextMenu ------------------------------ */
274
331
 
275
332
  const update_menuAnchorEl = React.useCallback((el) => {
@@ -283,74 +340,73 @@ function DataGrid(props: DataGridProps) {
283
340
  } else set_menuRow(null);
284
341
  }, []);
285
342
 
286
- /* -------------------------------------------------------------------------- */
287
- /* Create the grid */
288
- /* -------------------------------------------------------------------------- */
289
-
290
343
  const base_gridOptions = React.useMemo<GridOptions>(() => {
291
- const firstcolumn = columns[0];
292
- const licenseKey = props.licenseKey || get_default_key();
293
344
  const events: GridOptions = {
294
345
  onRowClick: onRowClick,
295
346
  onRowContextMenu: onRowContextMenu,
296
- onSkipChange: props.onSkipChange,
297
- onLimitChange: props.onLimitChange,
298
- onEditComplete: props.onEditComplete,
299
347
  };
300
- const extra_ops: GridOptions = {
301
- onSelectionChange: props.onSelectionChange,
302
- licenseKey: licenseKey,
303
- editable: props.editable,
304
- treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
305
- renderRowDetails: props.RowDetail,
306
- theme: dark ? 'amber-dark' : 'default-light',
307
- };
308
- return { ...defaultOptions, ...events, ...extra_ops };
309
- }, [
310
- columns,
311
- props.allowChildRows,
312
- props.editable,
313
- props.RowDetail,
314
- props.onEditComplete,
315
- ]);
316
-
317
- const static_gridOptions = React.useMemo<GridOptions>(() => {
318
- return { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
319
- }, [props.gridOptions, base_gridOptions, forcedOptions]);
348
+ return { ...props.base_gridOptions, ...events };
349
+ }, [props.base_gridOptions]);
320
350
 
321
- const dynamic_gridOptions = React.useMemo<GridOptions>(
322
- () => {
323
- const res = {};
324
- dynamic_option_names.map((r) => {
325
- res[r] = props[r];
326
- });
327
- return res;
328
- },
329
- dynamic_option_names.map((r) => props[r])
351
+ return (
352
+ <DataGridSizeWrapper {...props} base_gridOptions={base_gridOptions}>
353
+ <ContextMenu
354
+ menuAnchorEl={menuAnchorEl}
355
+ set_menuAnchorEl={update_menuAnchorEl}
356
+ menuRow={menuRow}
357
+ items={props.contextMenuItems}
358
+ />
359
+ {props.children}
360
+ </DataGridSizeWrapper>
330
361
  );
331
-
332
- // const { width, height, ref: resize_ref } = useResizeDetector();
333
-
362
+ }
363
+ function DataGridSizeWrapper(props: DataGridWrapperProps) {
364
+ if (props.delayedSize) {
365
+ return <DataGridDelayedSize {...props} />;
366
+ } else {
367
+ return <DataGridFlexSize {...props} />;
368
+ }
369
+ }
370
+ function DataGridDelayedSize(props: DataGridWrapperProps) {
371
+ const gridRef = React.useRef<any>(null);
372
+ const { ref, height, width } = useComponentSize();
373
+ return (
374
+ <div
375
+ ref={ref}
376
+ className={clsx(props.className, 'azgrid-nooverflow', 'azgrid-filler')}
377
+ >
378
+ <ReactDataGrid
379
+ {...props.static_gridOptions}
380
+ {...props.dynamic_gridOptions}
381
+ handle={(ref) => (gridRef.current = ref ? ref.current : null)}
382
+ className={'azgrid-delayedresize'}
383
+ style={{
384
+ height: height,
385
+ width: width,
386
+ }}
387
+ columns={props.columns}
388
+ dataSource={props.dataSource}
389
+ />
390
+ {props.children}
391
+ </div>
392
+ );
393
+ }
394
+ function DataGridFlexSize(props: DataGridWrapperProps) {
395
+ const gridRef = React.useRef<any>(null);
334
396
  return (
335
397
  <div className={clsx(props.className, 'azgrid-nooverflow', 'azgrid-filler')}>
336
398
  <ReactDataGrid
337
- {...static_gridOptions}
338
- {...dynamic_gridOptions}
399
+ {...props.static_gridOptions}
400
+ {...props.dynamic_gridOptions}
339
401
  handle={(ref) => (gridRef.current = ref ? ref.current : null)}
340
402
  className={'azgrid-filler'}
341
- columns={columns}
342
- dataSource={dataSource}
343
- />
344
- <ContextMenu
345
- menuAnchorEl={menuAnchorEl}
346
- set_menuAnchorEl={update_menuAnchorEl}
347
- menuRow={menuRow}
348
- items={contextMenuItems}
403
+ columns={props.columns}
404
+ dataSource={props.dataSource}
349
405
  />
406
+ {props.children}
350
407
  </div>
351
408
  );
352
409
  }
353
-
354
410
  /* -------------------------------------------------------------------------- */
355
411
  /* -------------------------------------------------------------------------- */
356
412
  /* -------------------------------------------------------------------------- */