@azrico/reactgrid 1.3.8 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
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.3.10](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.10) (2023-08-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * DataGridSearchWrapper ([ebf3acf](https://github.com/Azrideus/azrico-reactgrid/commit/ebf3acff5f90c45090fad86be8e83e28744dd9dd))
11
+ * editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * DataGridDelayedSizeWrapper actual delayed ([2ddfd2f](https://github.com/Azrideus/azrico-reactgrid/commit/2ddfd2fb58c90bd906e1330f22f0ef7468d34afb))
17
+ * onCellSelectionChange ([95c8f54](https://github.com/Azrideus/azrico-reactgrid/commit/95c8f540e94dde0c7e245fb29fb6afc7172957ec))
18
+ * styling ([9018f75](https://github.com/Azrideus/azrico-reactgrid/commit/9018f7593e253720f751f52855a2d956dfc578ed))
19
+
20
+ ### [1.3.9](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.9) (2023-08-19)
21
+
22
+
23
+ ### Features
24
+
25
+ * editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * DataGridDelayedSizeWrapper actual delayed ([2ddfd2f](https://github.com/Azrideus/azrico-reactgrid/commit/2ddfd2fb58c90bd906e1330f22f0ef7468d34afb))
31
+ * onCellSelectionChange ([95c8f54](https://github.com/Azrideus/azrico-reactgrid/commit/95c8f540e94dde0c7e245fb29fb6afc7172957ec))
32
+ * styling ([9018f75](https://github.com/Azrideus/azrico-reactgrid/commit/9018f7593e253720f751f52855a2d956dfc578ed))
33
+
5
34
  ### [1.3.8](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.8) (2023-08-19)
6
35
 
7
36
 
@@ -140,7 +140,6 @@ function ExampleGrid() {
140
140
  }];
141
141
  }, []);
142
142
  return _react.default.createElement(_DataGrid.default, {
143
- dark: true,
144
143
  delayedSize: true,
145
144
  // details_dataSource={details_dataSource}
146
145
  dataSource: dataSource,
@@ -156,6 +155,7 @@ function ExampleGrid() {
156
155
  editableColumns: editableColumns,
157
156
  editable: true,
158
157
  onEditComplete: onEditComplete,
158
+ advancedFilterFields: ['name'],
159
159
  // leftColumns={leftColumns}
160
160
  gridOptions: {
161
161
  // defaultFilterValue: filterValue,
@@ -12,6 +12,13 @@
12
12
  .azgrid-nooverflow {
13
13
  overflow: hidden;
14
14
  }
15
+ .azgrid-flexed {
16
+ flex: 1;
17
+ }
18
+ .azgrid-flexlayout {
19
+ display: flex;
20
+ flex-direction: column;
21
+ }
15
22
  .azgrid-testborder {
16
23
  border: 3px solid red;
17
24
  }
@@ -29,3 +36,17 @@
29
36
  transition-delay: 200ms;
30
37
  transition-duration: 0ms;
31
38
  }
39
+
40
+ .azgrid-searcharea {
41
+ margin: 5px;
42
+ font-size: large;
43
+ }
44
+ .azgrid-searcharea label {
45
+ gap: 5px;
46
+ display: flex;
47
+ align-items: center;
48
+ }
49
+ .azgrid-searcharea label input {
50
+ padding: 5px;
51
+ font-size: large;
52
+ }
@@ -68,6 +68,7 @@ export type AzGridProps = {
68
68
  skip?: number;
69
69
  limit?: number;
70
70
  editable?: boolean | ((editValue: any, cellProps: any) => boolean);
71
+ advancedFilterFields?: string[];
71
72
  loading?: boolean;
72
73
  dark?: boolean;
73
74
  delayedSize?: boolean;
@@ -14,9 +14,11 @@ var _func_grid = require("../func/func_grid");
14
14
  var _controls = require("@azrico/controls");
15
15
  var _react = _interopRequireWildcard(require("react"));
16
16
  var _func_child = require("../func/func_child");
17
+ var _object = require("@azrico/object");
17
18
  var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
18
19
  var _clsx = _interopRequireDefault(require("clsx"));
19
20
  var _reactUseSize = require("react-use-size");
21
+ var _lodash = _interopRequireDefault(require("lodash.debounce"));
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
  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
24
  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; }
@@ -54,8 +56,8 @@ function AzGrid(props) {
54
56
  const last_cache_info = _react.default.useRef();
55
57
  const dataSource = _react.default.useCallback(async dt => {
56
58
  return await (0, _func_grid.ApplyDataSource)(props.dataSource, {
57
- skip: dt.skip,
58
- limit: dt.limit,
59
+ skip: dt === null || dt === void 0 ? void 0 : dt.skip,
60
+ limit: dt === null || dt === void 0 ? void 0 : dt.limit,
59
61
  cached_data: cached_data,
60
62
  last_cache_info: last_cache_info
61
63
  });
@@ -241,12 +243,19 @@ function DataGridSizeWrapper(props) {
241
243
  ...props
242
244
  });
243
245
  } else {
244
- return _react.default.createElement(DataGridCore, {
246
+ return _react.default.createElement(DataGridNormalSizeWrapper, {
245
247
  ...props
246
248
  });
247
249
  }
248
250
  }
249
251
  /* -------------------------------------------------------------------------- */
252
+ function DataGridNormalSizeWrapper(props) {
253
+ return props.advancedFilterFields ? _react.default.createElement(DataGridSearchWrapper, {
254
+ ...props
255
+ }) : _react.default.createElement(DataGridCore, {
256
+ ...props
257
+ });
258
+ }
250
259
  function DataGridDelayedSizeWrapper(props) {
251
260
  const {
252
261
  ref,
@@ -255,26 +264,70 @@ function DataGridDelayedSizeWrapper(props) {
255
264
  } = (0, _reactUseSize.useComponentSize)();
256
265
  return _react.default.createElement("div", {
257
266
  ref: ref,
258
- className: 'azgrid-filler'
267
+ className: 'azgrid-filler azgrid-nooverflow '
259
268
  }, _react.default.createElement("div", {
260
- className: 'azgrid-delayedresize',
269
+ className: 'azgrid-delayedresize azgrid-flexlayout',
261
270
  style: {
262
271
  height: height,
263
272
  width: width
264
273
  }
265
- }, _react.default.createElement(DataGridCore, {
274
+ }, props.advancedFilterFields ? _react.default.createElement(DataGridSearchWrapper, {
275
+ ...props
276
+ }) : _react.default.createElement(DataGridCore, {
266
277
  ...props
267
278
  })));
268
279
  }
280
+ function DataGridSearchWrapper(props) {
281
+ const [search, set_search] = _react.default.useState('');
282
+ const [filteredData, set_filteredData] = _react.default.useState([]);
283
+ const [evaluatedDataSource, set_evaluatedDataSource] = _react.default.useState([]);
284
+ const try_search = _react.default.useCallback((0, _lodash.default)((ds, v) => {
285
+ if (!Array.isArray(ds)) return;
286
+ const visibleColumns = props.gridRef.current.visibleColumns;
287
+ const columns_to_search = (0, _object.array_intersection)(props.advancedFilterFields || [], visibleColumns.map(r => r.id));
288
+ const lowerSearchText = v && v.toLowerCase();
289
+ let newData = [];
290
+ if (!lowerSearchText) newData = ds;else newData = ds.filter(p => {
291
+ for (let index = 0; index < columns_to_search.length; index++) {
292
+ const col = columns_to_search[index];
293
+ const v = (p[col] + '').toLowerCase(); // get string value
294
+ if (v && v.indexOf(lowerSearchText) == -1) return false;
295
+ }
296
+ return true;
297
+ });
298
+ set_filteredData(newData);
299
+ }, 1000), []);
300
+ _react.default.useEffect(() => {
301
+ (0, _object.fn_eval)(props.dataSource).then(({
302
+ data
303
+ }) => set_evaluatedDataSource(data));
304
+ }, [props.dataSource]);
305
+ _react.default.useEffect(() => {
306
+ try_search(evaluatedDataSource, search);
307
+ }, [search, evaluatedDataSource]);
308
+ return _react.default.createElement("div", {
309
+ className: 'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'
310
+ }, _react.default.createElement("form", {
311
+ className: 'azgrid-searcharea'
312
+ }, _react.default.createElement("label", null, "Search", _react.default.createElement("input", {
313
+ type: "text",
314
+ name: "name",
315
+ value: search,
316
+ onChange: e => set_search(e.target.value)
317
+ }))), _react.default.createElement(DataGridCore, {
318
+ ...props,
319
+ dataSource: filteredData
320
+ }));
321
+ }
269
322
  function DataGridCore(props) {
270
323
  return _react.default.createElement("div", {
271
- className: (0, _clsx.default)(props.className, 'azgrid-filler')
324
+ className: (0, _clsx.default)(props.className, 'azgrid-flexed', 'azgrid-flexlayout')
272
325
  }, _react.default.createElement(_reactdatagridEnterprise.default, {
273
326
  ...props.static_gridOptions,
274
327
  ...props.dynamic_gridOptions,
275
328
  rowIndexColumn: true,
276
329
  handle: ref => props.gridRef.current = ref ? ref.current : null,
277
- className: 'azgrid-filler',
330
+ className: 'azgrid-flexed',
278
331
  columns: props.columns,
279
332
  dataSource: props.dataSource
280
333
  }), props.children);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -29,12 +29,13 @@
29
29
  "typescript": "^4.8.4"
30
30
  },
31
31
  "dependencies": {
32
- "@azrico/controls": "^1.5.58",
33
- "@azrico/object": "^1.4.35",
32
+ "@azrico/controls": "^1.5.60",
33
+ "@azrico/object": "^1.4.67",
34
34
  "@emotion/react": "^11.9.3",
35
35
  "@emotion/styled": "^11.9.3",
36
36
  "@inovua/reactdatagrid-enterprise": "^5.10.2",
37
37
  "clsx": "^2.0.0",
38
+ "lodash.debounce": "^4.0.8",
38
39
  "react": "^18.2.0",
39
40
  "react-use-size": "^3.0.1"
40
41
  },
package/src/example.tsx CHANGED
@@ -129,7 +129,6 @@ export function ExampleGrid() {
129
129
 
130
130
  return (
131
131
  <AzGrid
132
- dark
133
132
  delayedSize
134
133
  // details_dataSource={details_dataSource}
135
134
  dataSource={dataSource}
@@ -145,6 +144,7 @@ export function ExampleGrid() {
145
144
  editableColumns={editableColumns}
146
145
  editable={true}
147
146
  onEditComplete={onEditComplete}
147
+ advancedFilterFields={['name']}
148
148
  // leftColumns={leftColumns}
149
149
  gridOptions={
150
150
  {
@@ -12,6 +12,13 @@
12
12
  .azgrid-nooverflow {
13
13
  overflow: hidden;
14
14
  }
15
+ .azgrid-flexed {
16
+ flex: 1;
17
+ }
18
+ .azgrid-flexlayout {
19
+ display: flex;
20
+ flex-direction: column;
21
+ }
15
22
  .azgrid-testborder {
16
23
  border: 3px solid red;
17
24
  }
@@ -29,3 +36,17 @@
29
36
  transition-delay: 200ms;
30
37
  transition-duration: 0ms;
31
38
  }
39
+
40
+ .azgrid-searcharea {
41
+ margin: 5px;
42
+ font-size: large;
43
+ }
44
+ .azgrid-searcharea label {
45
+ gap: 5px;
46
+ display: flex;
47
+ align-items: center;
48
+ }
49
+ .azgrid-searcharea label input {
50
+ padding: 5px;
51
+ font-size: large;
52
+ }
@@ -28,13 +28,14 @@ import {
28
28
  TypeRowSelection,
29
29
  } from '@inovua/reactdatagrid-community/types';
30
30
  import { fix_parent_child_relations, func_selection } from '../func/func_child';
31
- import { fn_eval, object_equals } from '@azrico/object';
31
+ import { array_intersection, fn_eval } from '@azrico/object';
32
32
 
33
33
  import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
34
34
  import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
35
35
  import clsx from 'clsx';
36
36
  import { useComponentSize } from 'react-use-size';
37
37
 
38
+ import debounce from 'lodash.debounce';
38
39
  /* -------------------------------------------------------------------------- */
39
40
 
40
41
  /* -------------------------------------------------------------------------- */
@@ -112,8 +113,9 @@ export type AzGridProps = {
112
113
  limit?: number;
113
114
  //
114
115
  editable?: boolean | ((editValue: any, cellProps: any) => boolean);
115
-
116
+ advancedFilterFields?: string[];
116
117
  //
118
+
117
119
  loading?: boolean;
118
120
  dark?: boolean;
119
121
  delayedSize?: boolean;
@@ -184,8 +186,8 @@ export function AzGrid(props: AzGridProps) {
184
186
  const dataSource = React.useCallback(
185
187
  async (dt) => {
186
188
  return await ApplyDataSource(props.dataSource, {
187
- skip: dt.skip,
188
- limit: dt.limit,
189
+ skip: dt?.skip,
190
+ limit: dt?.limit,
189
191
  cached_data: cached_data,
190
192
  last_cache_info: last_cache_info,
191
193
  });
@@ -405,30 +407,99 @@ function DataGridSizeWrapper(props: DataGridWrapperProps) {
405
407
  if (props.delayedSize) {
406
408
  return <DataGridDelayedSizeWrapper {...props} />;
407
409
  } else {
408
- return <DataGridCore {...props} />;
410
+ return <DataGridNormalSizeWrapper {...props} />;
409
411
  }
410
412
  }
411
413
 
412
414
  /* -------------------------------------------------------------------------- */
415
+ function DataGridNormalSizeWrapper(props: DataGridWrapperProps) {
416
+ return props.advancedFilterFields ? (
417
+ <DataGridSearchWrapper {...props} />
418
+ ) : (
419
+ <DataGridCore {...props} />
420
+ );
421
+ }
413
422
  function DataGridDelayedSizeWrapper(props: DataGridWrapperProps) {
414
423
  const { ref, height, width } = useComponentSize();
415
424
  return (
416
- <div ref={ref} className={'azgrid-filler'}>
417
- <div className={'azgrid-delayedresize'} style={{ height: height, width: width }}>
418
- <DataGridCore {...props} />
425
+ <div ref={ref} className={'azgrid-filler azgrid-nooverflow '}>
426
+ <div
427
+ className={'azgrid-delayedresize azgrid-flexlayout'}
428
+ style={{ height: height, width: width }}
429
+ >
430
+ {props.advancedFilterFields ? (
431
+ <DataGridSearchWrapper {...props} />
432
+ ) : (
433
+ <DataGridCore {...props} />
434
+ )}
419
435
  </div>
420
436
  </div>
421
437
  );
422
438
  }
439
+ function DataGridSearchWrapper(props: DataGridWrapperProps) {
440
+ const [search, set_search] = React.useState('');
441
+ const [filteredData, set_filteredData] = React.useState<any[]>([]);
442
+ const [evaluatedDataSource, set_evaluatedDataSource] = React.useState<any[]>([]);
443
+
444
+ const try_search = React.useCallback(
445
+ debounce((ds, v) => {
446
+ if (!Array.isArray(ds)) return;
447
+ const visibleColumns = props.gridRef.current.visibleColumns;
448
+ const columns_to_search: string[] = array_intersection(
449
+ props.advancedFilterFields || [],
450
+ visibleColumns.map((r) => r.id)
451
+ );
452
+ const lowerSearchText = v && v.toLowerCase();
453
+ let newData: any[] = [];
454
+
455
+ if (!lowerSearchText) newData = ds;
456
+ else
457
+ newData = ds.filter((p) => {
458
+ for (let index = 0; index < columns_to_search.length; index++) {
459
+ const col = columns_to_search[index];
460
+ const v = (p[col] + '').toLowerCase(); // get string value
461
+
462
+ if (v && v.indexOf(lowerSearchText) == -1) return false;
463
+ }
464
+ return true;
465
+ });
466
+ set_filteredData(newData);
467
+ }, 1000),
468
+ []
469
+ );
470
+ React.useEffect(() => {
471
+ fn_eval(props.dataSource).then(({ data }) => set_evaluatedDataSource(data));
472
+ }, [props.dataSource]);
473
+ React.useEffect(() => {
474
+ try_search(evaluatedDataSource, search);
475
+ }, [search, evaluatedDataSource]);
476
+
477
+ return (
478
+ <div className={'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'}>
479
+ <form className={'azgrid-searcharea'}>
480
+ <label>
481
+ Search
482
+ <input
483
+ type="text"
484
+ name="name"
485
+ value={search}
486
+ onChange={(e) => set_search(e.target.value)}
487
+ />
488
+ </label>
489
+ </form>
490
+ <DataGridCore {...props} dataSource={filteredData} />
491
+ </div>
492
+ );
493
+ }
423
494
  function DataGridCore(props: DataGridWrapperProps) {
424
495
  return (
425
- <div className={clsx(props.className, 'azgrid-filler')}>
496
+ <div className={clsx(props.className, 'azgrid-flexed', 'azgrid-flexlayout')}>
426
497
  <ReactDataGrid
427
498
  {...props.static_gridOptions}
428
499
  {...props.dynamic_gridOptions}
429
500
  rowIndexColumn
430
501
  handle={(ref) => (props.gridRef.current = ref ? ref.current : null)}
431
- className={'azgrid-filler'}
502
+ className={'azgrid-flexed'}
432
503
  columns={props.columns}
433
504
  dataSource={props.dataSource}
434
505
  />