@azrico/reactgrid 1.3.49 → 1.3.52

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.
@@ -12,16 +12,16 @@ require("../themes/base_styles.css");
12
12
  require("../themes/grid.css");
13
13
  var _func_grid = require("../func/func_grid");
14
14
  var _controls = require("@azrico/controls");
15
- var _react = _interopRequireWildcard(require("react"));
16
- var _func_child = require("../func/func_child");
17
- var _object = require("@azrico/object");
15
+ var _react = _interopRequireDefault(require("react"));
18
16
  var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
19
17
  var _clsx = _interopRequireDefault(require("clsx"));
20
18
  var _reactUseSize = require("react-use-size");
21
- var _lodash = _interopRequireDefault(require("lodash.debounce"));
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ var _useGridEvents = require("../hooks/useGridEvents");
20
+ var _useColumnData = require("../hooks/useColumnData");
21
+ var _useDatasource = require("../hooks/useDatasource");
22
+ var _useGridSearch = require("../hooks/useGridSearch");
23
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
+ /* -------------------------------------------------------------------------- */
25
25
  /* -------------------------------------------------------------------------- */
26
26
  const defaultOptions = {
27
27
  //filterTypes: defaultfilterTypes,
@@ -46,22 +46,11 @@ function AzGrid(props) {
46
46
  /* -------------------------------------------------------------------------- */
47
47
  /* Columns */
48
48
  /* -------------------------------------------------------------------------- */
49
- const cached_columns = _react.default.useMemo(() => {
50
- return (0, _func_grid.ApplyColumnData)(props);
51
- }, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
49
+ const cached_columns = (0, _useColumnData.useColumnData)(props);
50
+ const dataSource = (0, _useDatasource.useDataSource)(props.dataSource, props);
52
51
  /* -------------------------------------------------------------------------- */
53
52
  /* Row changes */
54
53
  /* -------------------------------------------------------------------------- */
55
- const cached_data = _react.default.useRef();
56
- const last_cache_info = _react.default.useRef();
57
- const dataSource = _react.default.useCallback(async dt => {
58
- return await (0, _func_grid.ApplyDataSource)(props.dataSource, {
59
- skip: dt === null || dt === void 0 ? void 0 : dt.skip,
60
- limit: dt === null || dt === void 0 ? void 0 : dt.limit,
61
- cached_data: cached_data,
62
- last_cache_info: last_cache_info
63
- });
64
- }, [props.dataSource]);
65
54
  const base_gridOptions = _react.default.useMemo(() => {
66
55
  const firstcolumn = cached_columns[0];
67
56
  const licenseKey = props.licenseKey || (0, _func_grid.get_default_key)();
@@ -120,71 +109,14 @@ function AzGrid(props) {
120
109
  */
121
110
  function DataGridEventsWrapper(props) {
122
111
  /* -------------------------------------------------------------------------- */
123
- const click_data = _react.default.useRef(null);
124
- const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
125
- const [menuRow, set_menuRow] = _react.default.useState(null);
126
- /* -------------------------------------------------------------------------- */
127
- /* refresh functions */
128
- /* -------------------------------------------------------------------------- */
129
- const refreshColumn = _react.default.useCallback(col => {
130
- const dt = props.gridRef.current.ungroupedData;
131
- for (let index = 0; index < dt.length; index++) {
132
- props.gridRef.current.setItemPropertyAt(index, col, dt[index][col]);
133
- }
134
- }, [props.gridRef.current]);
135
- const refresh = _react.default.useCallback(() => {
136
- const dt = props.gridRef.current.ungroupedData;
137
- for (let index = 0; index < dt.length; index++) {
138
- props.gridRef.current.setItemAt(index, {}, {
139
- replace: false
140
- });
141
- }
142
- }, [props.gridRef.current]);
143
- _react.default.useEffect(() => {
144
- if (!props.gridRef.current) return;
145
- props.gridRef.current['refresh'] = refresh;
146
- props.gridRef.current['refreshColumn'] = refreshColumn;
147
- }, [props.gridRef.current, props.dataSource, refresh, refreshColumn]);
148
- /* -------------------------------------------------------------------------- */
149
- /* events */
150
- /* -------------------------------------------------------------------------- */
151
- const onRowClick = _react.default.useCallback((rowProps, event) => {
152
- const nowDate = Date.now();
153
- const lastclick = click_data.current[(0, _func_grid.get_row_id)(rowProps)];
154
- if (lastclick) {
155
- const diffTime = Math.abs(nowDate - lastclick);
156
- if (diffTime < 400) {
157
- click_data.current[(0, _func_grid.get_row_id)(rowProps)] = null;
158
- return props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
159
- }
160
- }
161
- click_data.current[(0, _func_grid.get_row_id)(rowProps)] = nowDate;
162
- return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
163
- }, [props.onRowClick, props.onRowDoubleClick]);
164
- _react.default.useEffect(() => {
165
- click_data.current = {};
166
- }, [props.dataSource]);
167
- /* ------------------------------- ContextMenu ------------------------------ */
168
- const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
169
- if (!rowProps || !rowProps.data || _func_child.func_selection.has_selection()) {
170
- update_menuRow(null, null);
171
- return true;
172
- }
173
- event.preventDefault();
174
- const realRow = (0, _func_grid.find_realData)(rowProps.dataSourceArray, event.target, rowProps.data);
175
- const anEl = _func_child.func_selection.getVirtualElement(event.clientX, event.clientY);
176
- update_menuRow(realRow, anEl);
177
- return false;
178
- }, []);
179
- const update_menuRow = _react.default.useCallback((r = null, el = null) => {
180
- set_menuRow(r || null);
181
- set_menuAnchorEl(el || null);
182
- }, []);
183
- /* -------------------------------------------------------------------------- */
184
- const onRenderRow = (0, _react.useCallback)(rowProps => {
185
- // save the original handlers to be called later
186
- rowProps['data-row-id'] = (0, _func_grid.get_row_id)(rowProps.data);
187
- }, []);
112
+ const {
113
+ onRowClick,
114
+ onRowContextMenu,
115
+ onRenderRow,
116
+ update_menuRow,
117
+ menuAnchorEl,
118
+ menuRow
119
+ } = (0, _useGridEvents.useGridEvents)(props.gridRef.current, props);
188
120
  /* -------------------------------------------------------------------------- */
189
121
  /**
190
122
  * Merge click events into grid options
@@ -220,20 +152,8 @@ function DataGridEventsWrapper(props) {
220
152
  }));
221
153
  }
222
154
  function DataGridDetailsWrapper(props) {
223
- const cached_details_columns = _react.default.useMemo(() => {
224
- return (0, _func_grid.ApplyColumnData)(props.details_columns);
225
- }, [props.details_columns]);
226
- const cached_data = _react.default.useRef();
227
- const last_cache_info = _react.default.useRef();
228
- const details_dataSource = _react.default.useCallback(async dt => {
229
- const res = await (0, _func_grid.ApplyDataSource)(props.details_dataSource, {
230
- skip: dt.skip,
231
- limit: dt.limit,
232
- cached_data: cached_data,
233
- last_cache_info: last_cache_info
234
- });
235
- return res;
236
- }, [props.details_dataSource]);
155
+ const cached_details_columns = (0, _useColumnData.useColumnData)(props.details_columns);
156
+ const details_dataSource = (0, _useDatasource.useDataSource)(props.details_dataSource, props);
237
157
  const renderDetailsGrid = ({
238
158
  data
239
159
  }) => {
@@ -297,60 +217,13 @@ function DataGridDelayedSizeWrapper(props) {
297
217
  })));
298
218
  }
299
219
  function DataGridSearchWrapper(props) {
300
- const [search, set_search] = _react.default.useState('');
301
- const [filteredData, set_filteredData] = _react.default.useState([]);
302
- const currentSearch = _react.default.useRef('');
303
- const currentDS = _react.default.useRef([]);
304
- const try_search = _react.default.useCallback((0, _lodash.default)(() => {
305
- if (!Array.isArray(currentDS.current)) {
306
- return;
307
- }
308
- let newData = [];
309
- if (currentSearch.current) {
310
- const visibleColumns = props.gridRef.current.visibleColumns;
311
- const columns_to_search = (0, _object.array_intersection)(props.advancedFilterFields || [], visibleColumns.map(r => r.id));
312
- const lowerSearchText = currentSearch.current.toLowerCase().trim();
313
- if (!lowerSearchText || columns_to_search.length === 0) newData = currentDS.current;else {
314
- newData = currentDS.current.filter(p => {
315
- for (let index = 0; index < columns_to_search.length; index++) {
316
- const col = columns_to_search[index];
317
- const v = (p[col] + '').toLowerCase(); //value of column
318
- if (v && v.indexOf(lowerSearchText) != -1) {
319
- //if one column is matching then the row is a match
320
- return true;
321
- }
322
- }
323
- return false;
324
- });
325
- }
326
- } else newData = currentDS.current;
327
- set_filteredData(newData);
328
- }, 1000), []);
329
- _react.default.useEffect(() => {
330
- (0, _object.fn_eval)(props.dataSource).then(r => {
331
- currentDS.current = typeof r === 'object' ? r.data || r : r;
332
- searchIfNeeded();
333
- });
334
- }, [props.dataSource]);
335
- _react.default.useEffect(() => {
336
- currentSearch.current = search;
337
- searchIfNeeded();
338
- }, [search]);
339
- function searchIfNeeded() {
340
- if (!search) {
341
- set_filteredData(props.dataSource);
342
- } else try_search();
343
- }
220
+ const {
221
+ element,
222
+ filteredData
223
+ } = (0, _useGridSearch.useGridSearch)(props.gridRef.current, props);
344
224
  return _react.default.createElement("div", {
345
225
  className: 'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'
346
- }, _react.default.createElement("form", {
347
- className: 'azgrid-searcharea'
348
- }, _react.default.createElement("label", null, "Search", _react.default.createElement("input", {
349
- type: "text",
350
- name: "name",
351
- value: search,
352
- onChange: e => set_search(e.target.value)
353
- }))), _react.default.createElement(DataGridCore, {
226
+ }, element, _react.default.createElement(DataGridCore, {
354
227
  ...props,
355
228
  dataSource: filteredData
356
229
  }));
@@ -18,5 +18,5 @@ Object.keys(_DataGrid).forEach(function (key) {
18
18
  });
19
19
  });
20
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
22
  var _default = exports.default = _DataGrid.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.3.49",
3
+ "version": "1.3.52",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
package/src/example.tsx CHANGED
@@ -1,10 +1,7 @@
1
1
  export * from './views/DataGrid';
2
2
 
3
3
  import AzGrid from './views/DataGrid';
4
- import { LooseColumnDefinition } from './views/DataGrid';
5
4
  import React from 'react';
6
- import ReactDOM from 'react-dom/client';
7
- import { getFormControlUtilityClasses } from '@mui/material';
8
5
 
9
6
  const columns = [
10
7
  {
@@ -30,7 +27,7 @@ const columns = [
30
27
  const editableColumns = ['job', 'age'];
31
28
 
32
29
  function getData(delta: any, max = 200) {
33
- const fd: any[] = [];
30
+ const fd: any[] = [];
34
31
  for (let index = 0; index < max; index++) {
35
32
  const currentObject = {
36
33
  __table_id: String(index),
@@ -102,9 +99,10 @@ export function ExampleGrid() {
102
99
 
103
100
  const onRowDoubleClick = React.useCallback((index: number, rowdata: any) => {
104
101
  console.log('dbl', rowdata?.data || rowdata);
102
+ alert('dbl: ' + index);
105
103
  }, []);
106
104
  const onRowClick = React.useCallback((index: number, rowdata: any) => {
107
- //console.log(rowdata?.data || rowdata);
105
+ console.log('click:', rowdata?.data || rowdata);
108
106
  }, []);
109
107
 
110
108
  React.useEffect(() => {
@@ -1,23 +1,23 @@
1
1
  type mrow = { __parent__table_id: any; __table_id: any; __children?: any[] };
2
2
  type converted_row = { parent: any; self: any; data: mrow };
3
3
 
4
- function get_parentId(obj) {
5
- return obj.__parent__table_id ?? obj.parent ?? obj.parentid;
4
+ function getParentId(obj) {
5
+ return obj.__parent__table_id ?? obj.parentid ?? obj.parent;
6
6
  }
7
- function get_selfId(obj) {
7
+ function getSelfId(obj) {
8
8
  return obj.__table_id ?? obj._id;
9
9
  }
10
10
  //given an array of rows, fixes parent,child relations
11
11
  export function fix_parent_child_relations<T extends mrow>(rows: T[]): T[] {
12
12
  if (!Array.isArray(rows)) rows = [];
13
- const anyparentid = rows.find((r) => get_parentId(r));
14
- const anyselfid = rows.find((r) => get_selfId(r));
13
+ const anyparentid = rows.find((r) => getParentId(r));
14
+ const anyselfid = rows.find((r) => getSelfId(r));
15
15
  if (!anyparentid || !anyselfid) return rows;
16
16
 
17
17
  const converted_rows: converted_row[] = rows
18
18
  .filter((r) => r != null)
19
19
  .map((r) => {
20
- return { parent: get_parentId(r), self: get_selfId(r), data: r };
20
+ return { parent: getParentId(r), self: getSelfId(r), data: r };
21
21
  });
22
22
 
23
23
  const top_level_rows: converted_row[] = converted_rows.filter((r) => !r.parent);
@@ -1,4 +1,4 @@
1
- import { ColumnDefinition, LooseColumnDefinition } from '../views/DataGrid';
1
+ import { ColumnDefinition, LooseColumnDefinition } from '../types/types';
2
2
 
3
3
  import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
4
4
  // import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
@@ -68,7 +68,7 @@ export async function ApplyDataSource(datasource, props) {
68
68
  * @param column_data
69
69
  * @returns
70
70
  */
71
- export function ApplyColumnData(column_data: any): ColumnDefinition[] {
71
+ export function applyColumnData(column_data: any): ColumnDefinition[] {
72
72
  const final_columns: MakeWriteable<LooseColumnDefinition>[] = [];
73
73
  if (!column_data) column_data = {};
74
74
  if (Array.isArray(column_data)) column_data = { columns: column_data };
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import {
3
+ AzGridProps,
4
+ DataGridWrapperProps,
5
+ GridType,
6
+ LooseColumnDefinition,
7
+ } from '../types/types';
8
+ import { applyColumnData, find_realData, get_row_id } from '../func/func_grid';
9
+ import { func_selection } from '../func/func_child';
10
+
11
+ export function useColumnData(
12
+ inputOrProps: undefined | any[] | LooseColumnDefinition[] | AzGridProps
13
+ ) {
14
+ if (inputOrProps == null) return [];
15
+ if (Array.isArray(inputOrProps)) return useThisColumnData(inputOrProps);
16
+ return usePropsColumnData(inputOrProps);
17
+ }
18
+ function useThisColumnData(cols: any[]) {
19
+ return React.useMemo(() => {
20
+ return applyColumnData(cols);
21
+ }, [cols]);
22
+ }
23
+ function usePropsColumnData(props: AzGridProps) {
24
+ return React.useMemo(() => {
25
+ return applyColumnData(props);
26
+ }, [
27
+ props.columns,
28
+ props.leftColumns,
29
+ props.rightColumns,
30
+ props.editableColumns,
31
+ props.columnExtensions,
32
+ props.customColumns,
33
+ ]);
34
+ }
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { AzGridProps, DataGridWrapperProps, GridType } from '../types/types';
3
+ import {
4
+ applyColumnData,
5
+ ApplyDataSource,
6
+ find_realData,
7
+ get_row_id,
8
+ } from '../func/func_grid';
9
+ import { func_selection } from '../func/func_child';
10
+
11
+ export function useDataSource(ds: any, props: AzGridProps) {
12
+ const cached_data = React.useRef<any>();
13
+ const last_cache_info = React.useRef<any>();
14
+ return React.useCallback(
15
+ async (dt) => {
16
+ return await ApplyDataSource(ds, {
17
+ skip: dt?.skip,
18
+ limit: dt?.limit,
19
+ cached_data: cached_data,
20
+ last_cache_info: last_cache_info,
21
+ });
22
+ },
23
+ [ds]
24
+ );
25
+ }
@@ -0,0 +1,96 @@
1
+ import React from 'react';
2
+ import { DataGridWrapperProps, GridType } from '../types/types';
3
+ import { find_realData, get_row_id } from '../func/func_grid';
4
+ import { func_selection } from '../func/func_child';
5
+
6
+ function useGridMenuRow() {
7
+ const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
8
+ const [menuRow, set_menuRow] = React.useState<any>(null);
9
+ const update_menuRow = React.useCallback((r: any = null, el: any = null) => {
10
+ set_menuRow(r || null);
11
+ set_menuAnchorEl(el || null);
12
+ }, []);
13
+ return { update_menuRow, menuAnchorEl, menuRow };
14
+ }
15
+ export function useGridEvents(grid: GridType, props: DataGridWrapperProps) {
16
+ const click_data = React.useRef<any>(null);
17
+ const { update_menuRow, menuAnchorEl, menuRow } = useGridMenuRow();
18
+
19
+ const refreshColumn = React.useCallback(
20
+ (col: string) => {
21
+ const dt = grid.ungroupedData;
22
+ for (let index = 0; index < dt.length; index++) {
23
+ (grid as any).setItemPropertyAt(index, col, dt[index][col]);
24
+ }
25
+ },
26
+ [grid]
27
+ );
28
+ const refresh = React.useCallback(() => {
29
+ const dt = grid.ungroupedData;
30
+ for (let index = 0; index < dt.length; index++) {
31
+ (grid as any).setItemAt(index, {}, { replace: false });
32
+ }
33
+ }, [grid]);
34
+
35
+ React.useEffect(() => {
36
+ if (!grid) return;
37
+ grid['refresh'] = refresh;
38
+ grid['refreshColumn'] = refreshColumn;
39
+ }, [grid, props.dataSource, refresh, refreshColumn]);
40
+ /* -------------------------------------------------------------------------- */
41
+ /* events */
42
+ /* -------------------------------------------------------------------------- */
43
+ const onRowClick = React.useCallback(
44
+ (rowProps, event) => {
45
+ const nowDate = Date.now();
46
+ const lastclick: number = click_data.current[get_row_id(rowProps)];
47
+ if (lastclick) {
48
+ const diffTime = Math.abs(nowDate - lastclick);
49
+ if (diffTime < 400) {
50
+ click_data.current[get_row_id(rowProps)] = null;
51
+ return (
52
+ props.onRowDoubleClick &&
53
+ props.onRowDoubleClick(rowProps.rowIndex, rowProps.data)
54
+ );
55
+ }
56
+ }
57
+
58
+ click_data.current[get_row_id(rowProps)] = nowDate;
59
+ return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
60
+ },
61
+ [props.onRowClick, props.onRowDoubleClick]
62
+ );
63
+
64
+ React.useEffect(() => {
65
+ click_data.current = {};
66
+ }, [props.dataSource]);
67
+
68
+ /* ------------------------------- ContextMenu ------------------------------ */
69
+ const onRowContextMenu = React.useCallback((rowProps, event) => {
70
+ if (!rowProps || !rowProps.data || func_selection.has_selection()) {
71
+ update_menuRow(null, null);
72
+ return true;
73
+ }
74
+ event.preventDefault();
75
+
76
+ const realRow = find_realData(rowProps.dataSourceArray, event.target, rowProps.data);
77
+ const anEl = func_selection.getVirtualElement(event.clientX, event.clientY);
78
+ update_menuRow(realRow, anEl);
79
+ return false;
80
+ }, []);
81
+
82
+ /* -------------------------------------------------------------------------- */
83
+ const onRenderRow = React.useCallback((rowProps) => {
84
+ // save the original handlers to be called later
85
+ rowProps['data-row-id'] = get_row_id(rowProps.data);
86
+ }, []);
87
+
88
+ return {
89
+ onRowClick,
90
+ onRowContextMenu,
91
+ onRenderRow,
92
+ update_menuRow,
93
+ menuAnchorEl,
94
+ menuRow,
95
+ };
96
+ }
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import { AzGridProps, DataGridWrapperProps, GridType } from '../types/types';
3
+ import debounce from 'lodash.debounce';
4
+ import { array_intersection, fn_eval } from '@azrico/object';
5
+
6
+ export function useGridSearch(grid: GridType, props: DataGridWrapperProps) {
7
+ const [search, set_search] = React.useState('');
8
+ const [filteredData, set_filteredData] = React.useState<any>([]);
9
+ const currentSearch = React.useRef('');
10
+ const currentDS = React.useRef<any[]>([]);
11
+
12
+ const try_search = React.useCallback(
13
+ debounce(() => {
14
+ if (!Array.isArray(currentDS.current)) {
15
+ return;
16
+ }
17
+ let newData: any[] = [];
18
+ if (currentSearch.current) {
19
+ const visibleColumns = grid.visibleColumns;
20
+ const columns_to_search: string[] = array_intersection(
21
+ props.advancedFilterFields || [],
22
+ visibleColumns.map((r) => r.id)
23
+ );
24
+ const lowerSearchText = currentSearch.current.toLowerCase().trim();
25
+ if (!lowerSearchText || columns_to_search.length === 0)
26
+ newData = currentDS.current;
27
+ else {
28
+ newData = currentDS.current.filter((p) => {
29
+ for (let index = 0; index < columns_to_search.length; index++) {
30
+ const col = columns_to_search[index];
31
+ const v = (p[col] + '').toLowerCase(); //value of column
32
+ if (v && v.indexOf(lowerSearchText) != -1) {
33
+ //if one column is matching then the row is a match
34
+ return true;
35
+ }
36
+ }
37
+ return false;
38
+ });
39
+ }
40
+ } else newData = currentDS.current;
41
+ set_filteredData(newData);
42
+ }, 1000),
43
+ [grid]
44
+ );
45
+ React.useEffect(() => {
46
+ fn_eval(props.dataSource).then((r) => {
47
+ currentDS.current = typeof r === 'object' ? r.data || r : r;
48
+ searchIfNeeded();
49
+ });
50
+ }, [props.dataSource]);
51
+
52
+ React.useEffect(() => {
53
+ currentSearch.current = search;
54
+ searchIfNeeded();
55
+ }, [search]);
56
+
57
+ function searchIfNeeded() {
58
+ if (!search) {
59
+ set_filteredData(props.dataSource);
60
+ } else try_search();
61
+ }
62
+
63
+ const element = (
64
+ <>
65
+ <form className={'azgrid-searcharea'}>
66
+ <label>
67
+ Search
68
+ <input
69
+ type="text"
70
+ name="name"
71
+ value={search}
72
+ onChange={(e) => set_search(e.target.value)}
73
+ />
74
+ </label>
75
+ </form>
76
+ </>
77
+ );
78
+ return { filteredData, element };
79
+ }
package/src/index.tsx CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './views/DataGrid';
2
+ export * from './types/types';
3
+
2
4
  export { get_row_id, set_row_id, get_col_name, get_col_header } from './func/func_grid';
3
5
 
4
6
  import AzGrid from './views/DataGrid';
@@ -38,15 +38,17 @@
38
38
  }
39
39
 
40
40
  .azgrid-searcharea {
41
+ font-family: 'Nunito Sans', 'Iran Sans', sans-serif;
41
42
  margin: 5px;
42
43
  font-size: large;
43
44
  }
44
45
  .azgrid-searcharea label {
45
- gap: 5px;
46
+ gap: 10px;
46
47
  display: flex;
47
48
  align-items: center;
48
49
  }
49
- .azgrid-searcharea label input {
50
+ .azgrid-searcharea input {
50
51
  padding: 5px;
52
+ padding-left: 7px;
51
53
  font-size: large;
52
54
  }
@@ -2,19 +2,19 @@
2
2
  z-index: 1000;
3
3
  font-family: 'Nunito Sans', 'Iran Sans', sans-serif;
4
4
  }
5
- .InovuaReactDataGrid--theme-amber-dark {
5
+
6
+ .InovuaReactDataGrid {
7
+ --grid-bg: oklch(var(--b1, 100% 0 106));
8
+ --grid-fg: oklch(var(--bc, 23.5% 0 0));
9
+ --grid-bg-hover: oklch(var(--b2, 94.75% 0.014 277.06));
10
+ --grid-bg-hover2: oklch(var(--b3, 94.75% 0.014 277.06));
11
+ --grid-fg-hover: oklch(var(--bc, 23.5% 0 0));
12
+ }.InovuaReactDataGrid--theme-amber-dark {
6
13
  --grid-bg: #313943;
7
14
  --grid-fg: #c5cae9;
8
- --grid-bg-hover: oklch(var(--b2, #313943));
15
+ --grid-bg-hover: oklch(var(--b2, 40.8% 0.011 128.75));
9
16
  --grid-fg-hover: #ececec;
10
17
  }
11
- .InovuaReactDataGrid {
12
- --grid-bg: oklch(var(--b1, #fff));
13
- --grid-fg: oklch(var(--bc, #1e1e1e));
14
- --grid-bg-hover: oklch(var(--b2, #ebedf7));
15
- --grid-bg-hover2: oklch(var(--b3, #ebedf7));
16
- --grid-fg-hover: oklch(var(--bc, #1e1e1e));
17
- }
18
18
  .InovuaReactDataGrid__row {
19
19
  color: var(--grid-fg);
20
20
  border-top-width: 1px;