@azrico/reactgrid 1.1.8 → 1.1.10

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.
@@ -51,25 +51,26 @@ function getData() {
51
51
  name: 'user-' + index,
52
52
  age: 20
53
53
  });
54
- if (index % 5 == 0) {
55
- const sub_selfid = 's' + index;
56
- fd.push({
57
- __table_id: sub_selfid,
58
- __parent__table_id: String(index),
59
- name: 'sub-' + index,
60
- age: 20
61
- });
62
- if (index % 2 == 0) {
63
- const sub2_selfid = 'ss' + index;
64
- fd.push({
65
- __table_id: sub2_selfid,
66
- __parent__table_id: sub_selfid,
67
- name: 'sub2-' + index,
68
- age: 20
69
- });
70
- }
71
- }
54
+ //if (index % 5 == 0) {
55
+ // const sub_selfid = 's' + index;
56
+ // fd.push({
57
+ // __table_id: sub_selfid,
58
+ // __parent__table_id: String(index),
59
+ // name: 'sub-' + index,
60
+ // age: 20,
61
+ // });
62
+ // if (index % 2 == 0) {
63
+ // const sub2_selfid = 'ss' + index;
64
+ // fd.push({
65
+ // __table_id: sub2_selfid,
66
+ // __parent__table_id: sub_selfid,
67
+ // name: 'sub2-' + index,
68
+ // age: 20,
69
+ // });
70
+ // }
71
+ //}
72
72
  }
73
+
73
74
  return fd;
74
75
  }
75
76
  function ExampleGrid() {
@@ -83,34 +84,40 @@ function ExampleGrid() {
83
84
  }, 1000);
84
85
  });
85
86
  }, [ds_reset]);
87
+ const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
88
+ console.log((rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
89
+ }, []);
90
+ const onRowClick = _react.default.useCallback((index, rowdata) => {
91
+ //console.log(rowdata?.data || rowdata);
92
+ }, []);
86
93
  function rst_ds() {
87
94
  //console.log('rst_ds');
88
95
  set_ds_reset(s => s + 1);
89
96
  }
90
- return _react.default.createElement("div", null, _react.default.createElement("div", {
91
- onClick: rst_ds
92
- }, "RESET"), _react.default.createElement(_DataGrid.default, {
97
+ return _react.default.createElement(_DataGrid.default, {
93
98
  dark: true,
94
- allowChildRows: true,
99
+ onRowClick: onRowClick,
100
+ onRowDoubleClick: onRowDoubleClick,
101
+ // allowChildRows
95
102
  // onSelectionChange={onSelectionChange}
96
103
  // selected={selected}
97
- contextMenuItems: contextMenuItems,
98
- customColumns: customColumns,
104
+ // contextMenuItems={contextMenuItems}
105
+ // customColumns={customColumns}
99
106
  columns: columns,
100
- leftColumns: leftColumns,
107
+ // leftColumns={leftColumns}
101
108
  gridOptions: {
102
- defaultFilterValue: filterValue,
103
- remoteFilter: false,
104
- multiSelect: true,
105
- pagination: 'local',
106
- defaultLimit: 100,
107
- limit: 100,
108
- pageSizes: [100],
109
- rowIndexColumn: true,
110
- checkboxColumn: true
109
+ // defaultFilterValue: filterValue,
110
+ // remoteFilter: false,
111
+ // multiSelect: true,
112
+ // pagination: 'local',
113
+ // defaultLimit: 100,
114
+ // limit: 100,
115
+ // pageSizes: [100],
116
+ // rowIndexColumn: true,
117
+ // checkboxColumn: true,
111
118
  },
112
119
  dataSource: dataSource
113
- }));
120
+ });
114
121
  }
115
122
  var _default = ExampleGrid;
116
123
  exports.default = _default;
package/dist/src/index.js CHANGED
@@ -19,6 +19,6 @@ Object.keys(_DataGrid).forEach(function (key) {
19
19
  });
20
20
  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); }
21
21
  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; }
22
- var _default = _DataGrid.default; //const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
23
- //root.render(<ExampleGrid />);
22
+ var _default = _DataGrid.default; // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
23
+ // root.render(<ExampleGrid />);
24
24
  exports.default = _default;
@@ -3,6 +3,7 @@ import '@inovua/reactdatagrid-enterprise/theme/default-dark.css';
3
3
  import '@inovua/reactdatagrid-enterprise/theme/amber-dark.css';
4
4
  import '../themes/base_styles.css';
5
5
  import '../themes/grid.css';
6
+ import { ConvertableToMenuItem } from '@azrico/controls';
6
7
  import React from 'react';
7
8
  import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeFilterTypes, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
8
9
  import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
@@ -44,7 +45,7 @@ export type AzGridProps = {
44
45
  leftColumns?: string[];
45
46
  rightColumns?: string[];
46
47
  customColumns?: customColumnData[];
47
- contextMenuItems?: any[];
48
+ contextMenuItems?: ConvertableToMenuItem[];
48
49
  highlightedRow?: any;
49
50
  RowDetail?: RowDetailsFunc;
50
51
  selected?: RowSelectionValue;
@@ -10,9 +10,9 @@ require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
10
10
  require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
11
11
  require("../themes/base_styles.css");
12
12
  require("../themes/grid.css");
13
+ var _controls = require("@azrico/controls");
13
14
  var _react = _interopRequireWildcard(require("react"));
14
15
  var _helpers = require("../func/helpers");
15
- var _controls = require("@azrico/controls");
16
16
  var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
17
17
  var _clsx = _interopRequireDefault(require("clsx"));
18
18
  var _object = require("@azrico/object");
@@ -120,8 +120,12 @@ function DataGrid(props) {
120
120
  } = props;
121
121
  /* -------------------------------------------------------------------------- */
122
122
  const gridRef = _react.default.useRef(null);
123
+ const click_data = _react.default.useRef(null);
123
124
  const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
124
125
  const [menuRow, set_menuRow] = _react.default.useState(null);
126
+ _react.default.useEffect(() => {
127
+ click_data.current = {};
128
+ }, [dataSource]);
125
129
  /* --------------------------------- events --------------------------------- */
126
130
  const onRowContextMenu = (0, _react.useCallback)((rowProps, event) => {
127
131
  if (_helpers.func_selection.has_selection()) return;
@@ -129,12 +133,18 @@ function DataGrid(props) {
129
133
  update_menuRow(rowProps.data);
130
134
  event.preventDefault();
131
135
  }, []);
132
- const onRowClick = (0, _react.useCallback)((rowProps, event) => {
136
+ const onRowClick = _react.default.useCallback((rowProps, event) => {
137
+ const nowDate = Date.now();
138
+ const lastclick = click_data.current[get_row_id(rowProps)];
139
+ if (lastclick) {
140
+ const diffTime = Math.abs(nowDate - lastclick);
141
+ if (diffTime < 400) {
142
+ props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
143
+ }
144
+ }
145
+ click_data.current[get_row_id(rowProps)] = nowDate;
133
146
  props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
134
147
  }, []);
135
- const onRowDoubleClick = _react.default.useCallback((event, rowProps) => {
136
- props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
137
- }, []);
138
148
  /* ------------------------------- ContextMenu ------------------------------ */
139
149
  const update_menuAnchorEl = _react.default.useCallback(el => {
140
150
  if (!el) {
@@ -154,7 +164,6 @@ function DataGrid(props) {
154
164
  const licenseKey = props.licenseKey || get_default_key();
155
165
  const events = {
156
166
  onRowClick: onRowClick,
157
- onRowDoubleClick: onRowDoubleClick,
158
167
  onSkipChange: props.onSkipChange,
159
168
  onLimitChange: props.onLimitChange,
160
169
  onRowContextMenu: onRowContextMenu
@@ -171,14 +180,14 @@ function DataGrid(props) {
171
180
  ...events,
172
181
  ...extra_ops
173
182
  };
174
- }, [columns, props.allowChildRows, props.RowDetail, onRowClick, onRowDoubleClick, onRowContextMenu]);
183
+ }, [columns, props.allowChildRows, props.RowDetail]);
175
184
  const static_gridOptions = _react.default.useMemo(() => {
176
185
  return {
177
186
  ...base_gridOptions,
178
187
  ...props.gridOptions,
179
188
  ...forcedOptions
180
189
  };
181
- }, [props.gridOptions, base_gridOptions]);
190
+ }, [props.gridOptions, base_gridOptions, forcedOptions]);
182
191
  const dynamic_gridOptions = _react.default.useMemo(() => {
183
192
  const res = {};
184
193
  dynamic_option_names.map(r => {
@@ -204,6 +213,9 @@ function DataGrid(props) {
204
213
  }));
205
214
  }
206
215
  /* -------------------------------------------------------------------------- */
216
+ /* -------------------------------------------------------------------------- */
217
+ /* -------------------------------------------------------------------------- */
218
+ /* -------------------------------------------------------------------------- */
207
219
  /**
208
220
  * Gets name of a column from its column object
209
221
  * @param obj
@@ -215,6 +227,17 @@ function get_col_name(obj) {
215
227
  if (typeof obj != 'object') return 'default';
216
228
  return obj.name || obj.field || obj.key || obj.columnName || 'default';
217
229
  }
230
+ /**
231
+ * Gets name of a column from its column object
232
+ * @param obj
233
+ * @returns
234
+ */
235
+ function get_row_id(obj) {
236
+ if (!obj) return 'default';
237
+ if (typeof obj == 'string') return obj;
238
+ if (typeof obj != 'object') return 'default';
239
+ return obj.__table_id || obj.id || 'default';
240
+ }
218
241
  /**
219
242
  * Gets default activation key for grid plugin
220
243
  * @returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -29,7 +29,7 @@
29
29
  "typescript": "^4.8.4"
30
30
  },
31
31
  "dependencies": {
32
- "@azrico/controls": "1.3.0",
32
+ "@azrico/controls": "1.3.6",
33
33
  "@azrico/object": "^1.3.1",
34
34
  "@emotion/react": "^11.9.3",
35
35
  "@emotion/styled": "^11.9.3",
package/src/example.tsx CHANGED
@@ -35,24 +35,24 @@ function getData() {
35
35
  const fd: any[] = [];
36
36
  for (let index = 0; index < 200; index++) {
37
37
  fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
38
- if (index % 5 == 0) {
39
- const sub_selfid = 's' + index;
40
- fd.push({
41
- __table_id: sub_selfid,
42
- __parent__table_id: String(index),
43
- name: 'sub-' + index,
44
- age: 20,
45
- });
46
- if (index % 2 == 0) {
47
- const sub2_selfid = 'ss' + index;
48
- fd.push({
49
- __table_id: sub2_selfid,
50
- __parent__table_id: sub_selfid,
51
- name: 'sub2-' + index,
52
- age: 20,
53
- });
54
- }
55
- }
38
+ //if (index % 5 == 0) {
39
+ // const sub_selfid = 's' + index;
40
+ // fd.push({
41
+ // __table_id: sub_selfid,
42
+ // __parent__table_id: String(index),
43
+ // name: 'sub-' + index,
44
+ // age: 20,
45
+ // });
46
+ // if (index % 2 == 0) {
47
+ // const sub2_selfid = 'ss' + index;
48
+ // fd.push({
49
+ // __table_id: sub2_selfid,
50
+ // __parent__table_id: sub_selfid,
51
+ // name: 'sub2-' + index,
52
+ // age: 20,
53
+ // });
54
+ // }
55
+ //}
56
56
  }
57
57
  return fd;
58
58
  }
@@ -73,37 +73,45 @@ export function ExampleGrid() {
73
73
  [ds_reset]
74
74
  );
75
75
 
76
+ const onRowDoubleClick = React.useCallback((index: number, rowdata: any) => {
77
+ console.log(rowdata?.data || rowdata);
78
+ }, []);
79
+ const onRowClick = React.useCallback((index: number, rowdata: any) => {
80
+ //console.log(rowdata?.data || rowdata);
81
+ }, []);
82
+
76
83
  function rst_ds() {
77
84
  //console.log('rst_ds');
78
85
  set_ds_reset((s) => s + 1);
79
86
  }
80
87
 
81
88
  return (
82
- <div>
83
- <div onClick={rst_ds}>RESET</div>
84
- <AzGrid
85
- dark
86
- allowChildRows
87
- // onSelectionChange={onSelectionChange}
88
- // selected={selected}
89
- contextMenuItems={contextMenuItems}
90
- customColumns={customColumns}
91
- columns={columns}
92
- leftColumns={leftColumns}
93
- gridOptions={{
94
- defaultFilterValue: filterValue,
95
- remoteFilter: false,
96
- multiSelect: true,
97
- pagination: 'local',
98
- defaultLimit: 100,
99
- limit: 100,
100
- pageSizes: [100],
101
- rowIndexColumn: true,
102
- checkboxColumn: true,
103
- }}
104
- dataSource={dataSource}
105
- />
106
- </div>
89
+ <AzGrid
90
+ dark
91
+ onRowClick={onRowClick}
92
+ onRowDoubleClick={onRowDoubleClick}
93
+ // allowChildRows
94
+ // onSelectionChange={onSelectionChange}
95
+ // selected={selected}
96
+ // contextMenuItems={contextMenuItems}
97
+ // customColumns={customColumns}
98
+ columns={columns}
99
+ // leftColumns={leftColumns}
100
+ gridOptions={
101
+ {
102
+ // defaultFilterValue: filterValue,
103
+ // remoteFilter: false,
104
+ // multiSelect: true,
105
+ // pagination: 'local',
106
+ // defaultLimit: 100,
107
+ // limit: 100,
108
+ // pageSizes: [100],
109
+ // rowIndexColumn: true,
110
+ // checkboxColumn: true,
111
+ }
112
+ }
113
+ dataSource={dataSource}
114
+ />
107
115
  );
108
116
  }
109
117
  export default ExampleGrid;
package/src/index.tsx CHANGED
@@ -7,5 +7,5 @@ import React from 'react';
7
7
  import ReactDOM from 'react-dom/client';
8
8
  export default AzGrid;
9
9
 
10
- //const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
11
- //root.render(<ExampleGrid />);
10
+ // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
11
+ // root.render(<ExampleGrid />);
@@ -4,6 +4,7 @@ import '@inovua/reactdatagrid-enterprise/theme/amber-dark.css';
4
4
  import '../themes/base_styles.css';
5
5
  import '../themes/grid.css';
6
6
 
7
+ import { ContextMenu, ConvertableToMenuItem } from '@azrico/controls';
7
8
  import React, { useCallback, useState } from 'react';
8
9
  import {
9
10
  TypeColumn,
@@ -16,7 +17,6 @@ import {
16
17
  } from '@inovua/reactdatagrid-community/types';
17
18
  import { fix_parent_child_relations, func_selection } from '../func/helpers';
18
19
 
19
- import { ContextMenu } from '@azrico/controls';
20
20
  import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
21
21
  import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
22
22
  import clsx from 'clsx';
@@ -70,7 +70,7 @@ export type AzGridProps = {
70
70
  rightColumns?: string[];
71
71
  customColumns?: customColumnData[];
72
72
 
73
- contextMenuItems?: any[];
73
+ contextMenuItems?: ConvertableToMenuItem[];
74
74
 
75
75
  highlightedRow?: any;
76
76
  RowDetail?: RowDetailsFunc;
@@ -220,10 +220,14 @@ function DataGrid(props: DataGridProps) {
220
220
 
221
221
  /* -------------------------------------------------------------------------- */
222
222
  const gridRef = React.useRef<any>(null);
223
+ const click_data = React.useRef<any>(null);
223
224
 
224
225
  const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
225
226
  const [menuRow, set_menuRow] = React.useState<any>(null);
226
227
 
228
+ React.useEffect(() => {
229
+ click_data.current = {};
230
+ }, [dataSource]);
227
231
  /* --------------------------------- events --------------------------------- */
228
232
 
229
233
  const onRowContextMenu = useCallback((rowProps, event) => {
@@ -232,12 +236,20 @@ function DataGrid(props: DataGridProps) {
232
236
  update_menuRow(rowProps.data);
233
237
  event.preventDefault();
234
238
  }, []);
235
- const onRowClick = useCallback((rowProps, event) => {
239
+ const onRowClick = React.useCallback((rowProps, event) => {
240
+ const nowDate = Date.now();
241
+ const lastclick: number = click_data.current[get_row_id(rowProps)];
242
+ if (lastclick) {
243
+ const diffTime = Math.abs(nowDate - lastclick);
244
+ if (diffTime < 400) {
245
+ props.onRowDoubleClick &&
246
+ props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
247
+ }
248
+ }
249
+
250
+ click_data.current[get_row_id(rowProps)] = nowDate;
236
251
  props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
237
252
  }, []);
238
- const onRowDoubleClick = React.useCallback((event, rowProps) => {
239
- props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
240
- }, []);
241
253
 
242
254
  /* ------------------------------- ContextMenu ------------------------------ */
243
255
  const update_menuAnchorEl = React.useCallback((el) => {
@@ -260,7 +272,6 @@ function DataGrid(props: DataGridProps) {
260
272
  const licenseKey = props.licenseKey || get_default_key();
261
273
  const events: GridOptions = {
262
274
  onRowClick: onRowClick,
263
- onRowDoubleClick: onRowDoubleClick,
264
275
  onSkipChange: props.onSkipChange,
265
276
  onLimitChange: props.onLimitChange,
266
277
  onRowContextMenu: onRowContextMenu,
@@ -273,18 +284,11 @@ function DataGrid(props: DataGridProps) {
273
284
  theme: dark ? 'amber-dark' : 'default-light',
274
285
  };
275
286
  return { ...defaultOptions, ...events, ...extra_ops };
276
- }, [
277
- columns,
278
- props.allowChildRows,
279
- props.RowDetail,
280
- onRowClick,
281
- onRowDoubleClick,
282
- onRowContextMenu,
283
- ]);
287
+ }, [columns, props.allowChildRows, props.RowDetail]);
284
288
 
285
289
  const static_gridOptions = React.useMemo<GridOptions>(() => {
286
290
  return { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
287
- }, [props.gridOptions, base_gridOptions]);
291
+ }, [props.gridOptions, base_gridOptions, forcedOptions]);
288
292
 
289
293
  const dynamic_gridOptions = React.useMemo<GridOptions>(
290
294
  () => {
@@ -319,6 +323,9 @@ function DataGrid(props: DataGridProps) {
319
323
  );
320
324
  }
321
325
 
326
+ /* -------------------------------------------------------------------------- */
327
+ /* -------------------------------------------------------------------------- */
328
+ /* -------------------------------------------------------------------------- */
322
329
  /* -------------------------------------------------------------------------- */
323
330
 
324
331
  /**
@@ -332,6 +339,17 @@ function get_col_name(obj: any): string {
332
339
  if (typeof obj != 'object') return 'default';
333
340
  return obj.name || obj.field || obj.key || obj.columnName || 'default';
334
341
  }
342
+ /**
343
+ * Gets name of a column from its column object
344
+ * @param obj
345
+ * @returns
346
+ */
347
+ function get_row_id(obj: any): any {
348
+ if (!obj) return 'default';
349
+ if (typeof obj == 'string') return obj;
350
+ if (typeof obj != 'object') return 'default';
351
+ return obj.__table_id || obj.id || 'default';
352
+ }
335
353
 
336
354
  /**
337
355
  * Gets default activation key for grid plugin