@azrico/reactgrid 1.3.14 → 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,21 @@
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
+
5
20
  ### [1.3.14](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.10...v1.3.14) (2023-08-19)
6
21
 
7
22
 
@@ -279,18 +279,19 @@ 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 (!Array.isArray(ds)) {
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)) {
286
287
  return;
287
288
  }
288
289
  let newData = [];
289
- if (v) {
290
+ if (currentSearch.current) {
290
291
  const visibleColumns = props.gridRef.current.visibleColumns;
291
292
  const columns_to_search = (0, _object.array_intersection)(props.advancedFilterFields || [], visibleColumns.map(r => r.id));
292
- const lowerSearchText = v && v.toLowerCase();
293
- if (!lowerSearchText) newData = ds;else newData = ds.filter(p => {
293
+ const lowerSearchText = currentSearch.current.toLowerCase();
294
+ if (!lowerSearchText) newData = currentDS.current;else newData = currentDS.current.filter(p => {
294
295
  for (let index = 0; index < columns_to_search.length; index++) {
295
296
  const col = columns_to_search[index];
296
297
  const v = (p[col] + '').toLowerCase(); // get string value
@@ -298,20 +299,27 @@ function DataGridSearchWrapper(props) {
298
299
  }
299
300
  return true;
300
301
  });
301
- } else newData = ds;
302
+ } else newData = currentDS.current;
302
303
  set_filteredData(newData);
303
304
  }, 1000), []);
304
305
  _react.default.useEffect(() => {
305
306
  set_search('');
306
307
  (0, _object.fn_eval)(props.dataSource).then(({
307
308
  data
308
- }) => set_evaluatedDataSource(data));
309
+ }) => {
310
+ currentDS.current = data;
311
+ searchIfNeeded();
312
+ });
309
313
  }, [props.dataSource]);
310
314
  _react.default.useEffect(() => {
315
+ currentSearch.current = search;
316
+ searchIfNeeded();
317
+ }, [search]);
318
+ function searchIfNeeded() {
311
319
  if (!search) {
312
320
  set_filteredData(props.dataSource);
313
- } else try_search(evaluatedDataSource, search);
314
- }, [search, evaluatedDataSource]);
321
+ } else try_search();
322
+ }
315
323
  return _react.default.createElement("div", {
316
324
  className: 'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'
317
325
  }, _react.default.createElement("form", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.3.14",
3
+ "version": "1.3.15",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -438,28 +438,26 @@ 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 (!Array.isArray(ds)) {
446
+ debounce(() => {
447
+ if (!Array.isArray(currentDS.current)) {
447
448
  return;
448
449
  }
449
-
450
450
  let newData: any[] = [];
451
-
452
- if (v) {
451
+ if (currentSearch.current) {
453
452
  const visibleColumns = props.gridRef.current.visibleColumns;
454
453
  const columns_to_search: string[] = array_intersection(
455
454
  props.advancedFilterFields || [],
456
455
  visibleColumns.map((r) => r.id)
457
456
  );
458
- const lowerSearchText = v && v.toLowerCase();
459
-
460
- if (!lowerSearchText) newData = ds;
457
+ const lowerSearchText = currentSearch.current.toLowerCase();
458
+ if (!lowerSearchText) newData = currentDS.current;
461
459
  else
462
- newData = ds.filter((p) => {
460
+ newData = currentDS.current.filter((p) => {
463
461
  for (let index = 0; index < columns_to_search.length; index++) {
464
462
  const col = columns_to_search[index];
465
463
  const v = (p[col] + '').toLowerCase(); // get string value
@@ -468,7 +466,7 @@ function DataGridSearchWrapper(props: DataGridWrapperProps) {
468
466
  }
469
467
  return true;
470
468
  });
471
- } else newData = ds;
469
+ } else newData = currentDS.current;
472
470
 
473
471
  set_filteredData(newData);
474
472
  }, 1000),
@@ -476,13 +474,22 @@ function DataGridSearchWrapper(props: DataGridWrapperProps) {
476
474
  );
477
475
  React.useEffect(() => {
478
476
  set_search('');
479
- fn_eval(props.dataSource).then(({ data }) => set_evaluatedDataSource(data));
477
+ fn_eval(props.dataSource).then(({ data }) => {
478
+ currentDS.current = data;
479
+ searchIfNeeded();
480
+ });
480
481
  }, [props.dataSource]);
482
+
481
483
  React.useEffect(() => {
484
+ currentSearch.current = search;
485
+ searchIfNeeded();
486
+ }, [search]);
487
+
488
+ function searchIfNeeded() {
482
489
  if (!search) {
483
490
  set_filteredData(props.dataSource);
484
- } else try_search(evaluatedDataSource, search);
485
- }, [search, evaluatedDataSource]);
491
+ } else try_search();
492
+ }
486
493
 
487
494
  return (
488
495
  <div className={'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'}>