@azrico/reactgrid 1.3.52 → 1.3.54
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 +533 -533
- package/dist/src/example.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/themes/grid.css +9 -2
- package/dist/src/views/index.js +1 -2
- package/package.json +2 -2
- package/public/manifest.json +9 -9
- package/src/hooks/useColumnData.ts +34 -34
- package/src/hooks/useDatasource.ts +25 -25
- package/src/hooks/useGridEvents.ts +96 -96
- package/src/hooks/useGridSearch.tsx +79 -79
- package/src/themes/grid.css +9 -2
- package/src/types/types.ts +122 -122
- package/src/views/DataGrid.tsx +1 -4
- package/src/views/index.ts +4 -4
package/dist/src/example.js
CHANGED
|
@@ -22,8 +22,7 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
22
22
|
});
|
|
23
23
|
var _react = _interopRequireDefault(require("react"));
|
|
24
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
|
-
function
|
|
26
|
-
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; }
|
|
25
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
27
26
|
const columns = [{
|
|
28
27
|
name: 'name',
|
|
29
28
|
title: 'Name',
|
package/dist/src/index.js
CHANGED
|
@@ -63,8 +63,7 @@ var _example = _interopRequireDefault(require("./example"));
|
|
|
63
63
|
var _react = _interopRequireDefault(require("react"));
|
|
64
64
|
var _client = _interopRequireDefault(require("react-dom/client"));
|
|
65
65
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
66
|
-
function
|
|
67
|
-
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; }
|
|
66
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
68
67
|
/* -------------------------------------------------------------------------- */
|
|
69
68
|
//
|
|
70
69
|
var _default = exports.default = _DataGrid.default;
|
package/dist/src/themes/grid.css
CHANGED
|
@@ -9,15 +9,22 @@
|
|
|
9
9
|
--grid-bg-hover: oklch(var(--b2, 94.75% 0.014 277.06));
|
|
10
10
|
--grid-bg-hover2: oklch(var(--b3, 94.75% 0.014 277.06));
|
|
11
11
|
--grid-fg-hover: oklch(var(--bc, 23.5% 0 0));
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.InovuaReactDataGrid--theme-amber-dark {
|
|
13
15
|
--grid-bg: #313943;
|
|
14
16
|
--grid-fg: #c5cae9;
|
|
15
17
|
--grid-bg-hover: oklch(var(--b2, 40.8% 0.011 128.75));
|
|
16
18
|
--grid-fg-hover: #ececec;
|
|
17
19
|
}
|
|
18
20
|
.InovuaReactDataGrid__row {
|
|
21
|
+
border: none !important;
|
|
22
|
+
border-top-width: 0 !important;
|
|
23
|
+
border-bottom-width: 0 !important;
|
|
19
24
|
color: var(--grid-fg);
|
|
20
|
-
|
|
25
|
+
}
|
|
26
|
+
.InovuaReactDataGrid__cell {
|
|
27
|
+
border: 0.1px solid rgba(1, 1, 1, 0.1) !important ;
|
|
21
28
|
}
|
|
22
29
|
.InovuaReactDataGrid--theme-default-light .InovuaReactDataGrid__row--odd {
|
|
23
30
|
background-color: #fafafa;
|
package/dist/src/views/index.js
CHANGED
|
@@ -17,6 +17,5 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
|
-
function
|
|
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; }
|
|
20
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
22
21
|
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.
|
|
3
|
+
"version": "1.3.54",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "React Datagrid",
|
|
6
6
|
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"last 1 safari version"
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
-
"packageManager": "yarn@
|
|
64
|
+
"packageManager": "yarn@4.10.2"
|
|
65
65
|
}
|
package/public/manifest.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"short_name": "AzGrid",
|
|
3
|
-
"name": "React Grid Wrapper",
|
|
4
|
-
"icons": [],
|
|
5
|
-
"start_url": "./index.html",
|
|
6
|
-
"display": "standalone",
|
|
7
|
-
"theme_color": "#000000",
|
|
8
|
-
"background_color": "#ffffff"
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"short_name": "AzGrid",
|
|
3
|
+
"name": "React Grid Wrapper",
|
|
4
|
+
"icons": [],
|
|
5
|
+
"start_url": "./index.html",
|
|
6
|
+
"display": "standalone",
|
|
7
|
+
"theme_color": "#000000",
|
|
8
|
+
"background_color": "#ffffff"
|
|
9
|
+
}
|
|
@@ -1,34 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,25 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,96 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,79 +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
|
-
}
|
|
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/themes/grid.css
CHANGED
|
@@ -9,15 +9,22 @@
|
|
|
9
9
|
--grid-bg-hover: oklch(var(--b2, 94.75% 0.014 277.06));
|
|
10
10
|
--grid-bg-hover2: oklch(var(--b3, 94.75% 0.014 277.06));
|
|
11
11
|
--grid-fg-hover: oklch(var(--bc, 23.5% 0 0));
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.InovuaReactDataGrid--theme-amber-dark {
|
|
13
15
|
--grid-bg: #313943;
|
|
14
16
|
--grid-fg: #c5cae9;
|
|
15
17
|
--grid-bg-hover: oklch(var(--b2, 40.8% 0.011 128.75));
|
|
16
18
|
--grid-fg-hover: #ececec;
|
|
17
19
|
}
|
|
18
20
|
.InovuaReactDataGrid__row {
|
|
21
|
+
border: none !important;
|
|
22
|
+
border-top-width: 0 !important;
|
|
23
|
+
border-bottom-width: 0 !important;
|
|
19
24
|
color: var(--grid-fg);
|
|
20
|
-
|
|
25
|
+
}
|
|
26
|
+
.InovuaReactDataGrid__cell {
|
|
27
|
+
border: 0.1px solid rgba(1, 1, 1, 0.1) !important ;
|
|
21
28
|
}
|
|
22
29
|
.InovuaReactDataGrid--theme-default-light .InovuaReactDataGrid__row--odd {
|
|
23
30
|
background-color: #fafafa;
|