@azrico/reactgrid 1.3.13 → 1.3.15

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,36 @@
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.15](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.15) (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.14](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.14) (2023-08-19)
21
+
22
+
23
+ ### Features
24
+
25
+ * DataGridSearchWrapper ([ebf3acf](https://github.com/Azrideus/azrico-reactgrid/commit/ebf3acff5f90c45090fad86be8e83e28744dd9dd))
26
+ * editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * DataGridDelayedSizeWrapper actual delayed ([2ddfd2f](https://github.com/Azrideus/azrico-reactgrid/commit/2ddfd2fb58c90bd906e1330f22f0ef7468d34afb))
32
+ * onCellSelectionChange ([95c8f54](https://github.com/Azrideus/azrico-reactgrid/commit/95c8f540e94dde0c7e245fb29fb6afc7172957ec))
33
+ * styling ([9018f75](https://github.com/Azrideus/azrico-reactgrid/commit/9018f7593e253720f751f52855a2d956dfc578ed))
34
+
5
35
  ### [1.3.13](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.13) (2023-08-19)
6
36
 
7
37
 
@@ -279,38 +279,47 @@ function DataGridDelayedSizeWrapper(props) {
279
279
  }
280
280
  function DataGridSearchWrapper(props) {
281
281
  const [search, set_search] = _react.default.useState('');
282
- const [evaluatedDataSource, set_evaluatedDataSource] = _react.default.useState([]);
283
282
  const [filteredData, set_filteredData] = _react.default.useState([]);
284
- const try_search = _react.default.useCallback((0, _lodash.default)((ds, v) => {
285
- if (!search || !Array.isArray(ds)) {
286
- set_filteredData(props.dataSource);
283
+ const currentSearch = _react.default.useRef('');
284
+ const currentDS = _react.default.useRef([]);
285
+ const try_search = _react.default.useCallback((0, _lodash.default)(() => {
286
+ if (!Array.isArray(currentDS.current)) {
287
287
  return;
288
288
  }
289
- const visibleColumns = props.gridRef.current.visibleColumns;
290
- const columns_to_search = (0, _object.array_intersection)(props.advancedFilterFields || [], visibleColumns.map(r => r.id));
291
- const lowerSearchText = v && v.toLowerCase();
292
289
  let newData = [];
293
- if (!lowerSearchText) newData = ds;else newData = ds.filter(p => {
294
- for (let index = 0; index < columns_to_search.length; index++) {
295
- const col = columns_to_search[index];
296
- const v = (p[col] + '').toLowerCase(); // get string value
297
- if (v && v.indexOf(lowerSearchText) == -1) return false;
298
- }
299
- return true;
300
- });
290
+ if (currentSearch.current) {
291
+ const visibleColumns = props.gridRef.current.visibleColumns;
292
+ const columns_to_search = (0, _object.array_intersection)(props.advancedFilterFields || [], visibleColumns.map(r => r.id));
293
+ const lowerSearchText = currentSearch.current.toLowerCase();
294
+ if (!lowerSearchText) newData = currentDS.current;else newData = currentDS.current.filter(p => {
295
+ for (let index = 0; index < columns_to_search.length; index++) {
296
+ const col = columns_to_search[index];
297
+ const v = (p[col] + '').toLowerCase(); // get string value
298
+ if (v && v.indexOf(lowerSearchText) == -1) return false;
299
+ }
300
+ return true;
301
+ });
302
+ } else newData = currentDS.current;
301
303
  set_filteredData(newData);
302
304
  }, 1000), []);
303
305
  _react.default.useEffect(() => {
304
306
  set_search('');
305
307
  (0, _object.fn_eval)(props.dataSource).then(({
306
308
  data
307
- }) => set_evaluatedDataSource(data));
309
+ }) => {
310
+ currentDS.current = data;
311
+ searchIfNeeded();
312
+ });
308
313
  }, [props.dataSource]);
309
314
  _react.default.useEffect(() => {
315
+ currentSearch.current = search;
316
+ searchIfNeeded();
317
+ }, [search]);
318
+ function searchIfNeeded() {
310
319
  if (!search) {
311
320
  set_filteredData(props.dataSource);
312
- } else try_search(evaluatedDataSource, search);
313
- }, [search, evaluatedDataSource]);
321
+ } else try_search();
322
+ }
314
323
  return _react.default.createElement("div", {
315
324
  className: 'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'
316
325
  }, _react.default.createElement("form", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -438,47 +438,58 @@ function DataGridDelayedSizeWrapper(props: DataGridWrapperProps) {
438
438
  }
439
439
  function DataGridSearchWrapper(props: DataGridWrapperProps) {
440
440
  const [search, set_search] = React.useState('');
441
- const [evaluatedDataSource, set_evaluatedDataSource] = React.useState<any[]>([]);
442
441
  const [filteredData, set_filteredData] = React.useState<any>([]);
442
+ const currentSearch = React.useRef('');
443
+ const currentDS = React.useRef<any[]>([]);
443
444
 
444
445
  const try_search = React.useCallback(
445
- debounce((ds, v) => {
446
- if (!search || !Array.isArray(ds)) {
447
- set_filteredData(props.dataSource);
446
+ debounce(() => {
447
+ if (!Array.isArray(currentDS.current)) {
448
448
  return;
449
449
  }
450
- const visibleColumns = props.gridRef.current.visibleColumns;
451
- const columns_to_search: string[] = array_intersection(
452
- props.advancedFilterFields || [],
453
- visibleColumns.map((r) => r.id)
454
- );
455
- const lowerSearchText = v && v.toLowerCase();
456
450
  let newData: any[] = [];
451
+ if (currentSearch.current) {
452
+ const visibleColumns = props.gridRef.current.visibleColumns;
453
+ const columns_to_search: string[] = array_intersection(
454
+ props.advancedFilterFields || [],
455
+ visibleColumns.map((r) => r.id)
456
+ );
457
+ const lowerSearchText = currentSearch.current.toLowerCase();
458
+ if (!lowerSearchText) newData = currentDS.current;
459
+ else
460
+ newData = currentDS.current.filter((p) => {
461
+ for (let index = 0; index < columns_to_search.length; index++) {
462
+ const col = columns_to_search[index];
463
+ const v = (p[col] + '').toLowerCase(); // get string value
464
+
465
+ if (v && v.indexOf(lowerSearchText) == -1) return false;
466
+ }
467
+ return true;
468
+ });
469
+ } else newData = currentDS.current;
457
470
 
458
- if (!lowerSearchText) newData = ds;
459
- else
460
- newData = ds.filter((p) => {
461
- for (let index = 0; index < columns_to_search.length; index++) {
462
- const col = columns_to_search[index];
463
- const v = (p[col] + '').toLowerCase(); // get string value
464
-
465
- if (v && v.indexOf(lowerSearchText) == -1) return false;
466
- }
467
- return true;
468
- });
469
471
  set_filteredData(newData);
470
472
  }, 1000),
471
473
  []
472
474
  );
473
475
  React.useEffect(() => {
474
476
  set_search('');
475
- fn_eval(props.dataSource).then(({ data }) => set_evaluatedDataSource(data));
477
+ fn_eval(props.dataSource).then(({ data }) => {
478
+ currentDS.current = data;
479
+ searchIfNeeded();
480
+ });
476
481
  }, [props.dataSource]);
482
+
477
483
  React.useEffect(() => {
484
+ currentSearch.current = search;
485
+ searchIfNeeded();
486
+ }, [search]);
487
+
488
+ function searchIfNeeded() {
478
489
  if (!search) {
479
490
  set_filteredData(props.dataSource);
480
- } else try_search(evaluatedDataSource, search);
481
- }, [search, evaluatedDataSource]);
491
+ } else try_search();
492
+ }
482
493
 
483
494
  return (
484
495
  <div className={'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'}>