@azrico/reactgrid 1.0.23 → 1.1.1
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/dist/src/example.js +23 -45
- package/dist/src/index.js +9 -3
- package/dist/src/views/DataGrid.d.ts +2 -1
- package/dist/src/views/DataGrid.js +54 -3
- package/package.json +2 -1
- package/src/example.tsx +42 -51
- package/src/index.tsx +2 -2
- package/src/views/DataGrid.tsx +63 -5
package/dist/src/example.js
CHANGED
|
@@ -25,20 +25,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
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); }
|
|
26
26
|
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; }
|
|
27
27
|
const columns = [{
|
|
28
|
-
name: '
|
|
29
|
-
title: '
|
|
30
|
-
|
|
31
|
-
}, {
|
|
32
|
-
name: 'job',
|
|
33
|
-
title: 'Job'
|
|
34
|
-
}, {
|
|
35
|
-
name: 'age',
|
|
36
|
-
title: 'Age',
|
|
37
|
-
editor: 'input'
|
|
38
|
-
}, {
|
|
39
|
-
title: 'Example',
|
|
40
|
-
field: 'example',
|
|
41
|
-
editor: 'input'
|
|
28
|
+
name: 'name',
|
|
29
|
+
title: 'Category',
|
|
30
|
+
defaultFlex: 1
|
|
42
31
|
}];
|
|
43
32
|
const leftColumns = ['username', 'row'];
|
|
44
33
|
const customColumns = [{
|
|
@@ -47,13 +36,19 @@ const customColumns = [{
|
|
|
47
36
|
return _react.default.createElement("div", null, "test");
|
|
48
37
|
}
|
|
49
38
|
}];
|
|
39
|
+
const filterValue = [{
|
|
40
|
+
name: 'name',
|
|
41
|
+
operator: 'contains',
|
|
42
|
+
type: 'string',
|
|
43
|
+
value: ''
|
|
44
|
+
}];
|
|
50
45
|
const contextMenuItems = ['test'];
|
|
51
46
|
function getData() {
|
|
52
47
|
const fd = [];
|
|
53
|
-
for (let index = 0; index <
|
|
48
|
+
for (let index = 0; index < 200; index++) {
|
|
54
49
|
fd.push({
|
|
55
50
|
__table_id: String(index),
|
|
56
|
-
|
|
51
|
+
name: 'user-' + index,
|
|
57
52
|
age: 20
|
|
58
53
|
});
|
|
59
54
|
if (index % 5 == 0) {
|
|
@@ -61,7 +56,7 @@ function getData() {
|
|
|
61
56
|
fd.push({
|
|
62
57
|
__table_id: sub_selfid,
|
|
63
58
|
__parent__table_id: String(index),
|
|
64
|
-
|
|
59
|
+
name: 'sub-' + index,
|
|
65
60
|
age: 20
|
|
66
61
|
});
|
|
67
62
|
if (index % 2 == 0) {
|
|
@@ -69,7 +64,7 @@ function getData() {
|
|
|
69
64
|
fd.push({
|
|
70
65
|
__table_id: sub2_selfid,
|
|
71
66
|
__parent__table_id: sub_selfid,
|
|
72
|
-
|
|
67
|
+
name: 'sub2-' + index,
|
|
73
68
|
age: 20
|
|
74
69
|
});
|
|
75
70
|
}
|
|
@@ -77,6 +72,7 @@ function getData() {
|
|
|
77
72
|
}
|
|
78
73
|
return fd;
|
|
79
74
|
}
|
|
75
|
+
//TODO REMOTE FILTER OFF ?
|
|
80
76
|
function ExampleGrid() {
|
|
81
77
|
const [selected, setSelected] = _react.default.useState(null);
|
|
82
78
|
const onSelectionChange = _react.default.useCallback(({
|
|
@@ -89,42 +85,24 @@ function ExampleGrid() {
|
|
|
89
85
|
return await new Promise(resolve => {
|
|
90
86
|
setTimeout(() => {
|
|
91
87
|
console.log('end loading');
|
|
92
|
-
resolve(
|
|
93
|
-
data: getData(),
|
|
94
|
-
count: 999
|
|
95
|
-
});
|
|
88
|
+
resolve(getData());
|
|
96
89
|
}, 1000);
|
|
97
90
|
});
|
|
98
91
|
}, []);
|
|
99
|
-
return _react.default.createElement(
|
|
100
|
-
dark: true,
|
|
101
|
-
allowChildRows: true,
|
|
102
|
-
onSelectionChange: onSelectionChange,
|
|
103
|
-
selected: selected,
|
|
104
|
-
contextMenuItems: contextMenuItems,
|
|
105
|
-
customColumns: customColumns,
|
|
106
|
-
columns: columns,
|
|
107
|
-
leftColumns: leftColumns,
|
|
108
|
-
gridOptions: {
|
|
109
|
-
pagination: 'remote',
|
|
110
|
-
defaultLimit: 100,
|
|
111
|
-
limit: 100,
|
|
112
|
-
pageSizes: [100],
|
|
113
|
-
rowIndexColumn: true,
|
|
114
|
-
checkboxColumn: true
|
|
115
|
-
},
|
|
116
|
-
dataSource: dataSource
|
|
117
|
-
}), _react.default.createElement(_DataGrid.default, {
|
|
92
|
+
return _react.default.createElement(_DataGrid.default, {
|
|
118
93
|
dark: true,
|
|
119
94
|
allowChildRows: true,
|
|
120
|
-
|
|
121
|
-
|
|
95
|
+
// onSelectionChange={onSelectionChange}
|
|
96
|
+
// selected={selected}
|
|
122
97
|
contextMenuItems: contextMenuItems,
|
|
123
98
|
customColumns: customColumns,
|
|
124
99
|
columns: columns,
|
|
125
100
|
leftColumns: leftColumns,
|
|
126
101
|
gridOptions: {
|
|
127
|
-
|
|
102
|
+
defaultFilterValue: filterValue,
|
|
103
|
+
remoteFilter: false,
|
|
104
|
+
multiSelect: true,
|
|
105
|
+
pagination: 'local',
|
|
128
106
|
defaultLimit: 100,
|
|
129
107
|
limit: 100,
|
|
130
108
|
pageSizes: [100],
|
|
@@ -132,7 +110,7 @@ function ExampleGrid() {
|
|
|
132
110
|
checkboxColumn: true
|
|
133
111
|
},
|
|
134
112
|
dataSource: dataSource
|
|
135
|
-
})
|
|
113
|
+
});
|
|
136
114
|
}
|
|
137
115
|
var _default = ExampleGrid;
|
|
138
116
|
exports.default = _default;
|
package/dist/src/index.js
CHANGED
|
@@ -17,8 +17,14 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
|
+
var _example = _interopRequireDefault(require("./example"));
|
|
21
|
+
var _react = _interopRequireDefault(require("react"));
|
|
22
|
+
var _client = _interopRequireDefault(require("react-dom/client"));
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
24
|
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); }
|
|
21
25
|
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; }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
exports.default = _default;
|
|
26
|
+
/* -------------------------------------------------------------------------- */
|
|
27
|
+
var _default = _DataGrid.default;
|
|
28
|
+
exports.default = _default;
|
|
29
|
+
const root = _client.default.createRoot(document.getElementById('root'));
|
|
30
|
+
root.render(_react.default.createElement(_example.default, null));
|
|
@@ -4,7 +4,7 @@ import '@inovua/reactdatagrid-enterprise/theme/amber-dark.css';
|
|
|
4
4
|
import '../themes/base_styles.css';
|
|
5
5
|
import '../themes/grid.css';
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
|
|
7
|
+
import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeFilterTypes, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
|
|
8
8
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
9
9
|
export type ColumnDefinition = TypeColumn;
|
|
10
10
|
export type CellDefinition = any;
|
|
@@ -12,6 +12,7 @@ export type RowDefinition = any;
|
|
|
12
12
|
export type RowProps = TypeRowProps;
|
|
13
13
|
export type RowSelectionValue = TypeRowSelection;
|
|
14
14
|
export type DataRowDefinition = any;
|
|
15
|
+
export type FilterTypes = TypeFilterTypes;
|
|
15
16
|
export type DataSourceDefinition = TypeDataSource;
|
|
16
17
|
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
17
18
|
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
@@ -15,9 +15,28 @@ var _helpers = require("../func/helpers");
|
|
|
15
15
|
var _controls = require("@azrico/controls");
|
|
16
16
|
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
17
17
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
18
|
+
var _object = require("@azrico/object");
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
20
|
/* -------------------------------------------------------------------------- */
|
|
21
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
22
|
+
// string: {
|
|
23
|
+
// type: 'string',
|
|
24
|
+
// emptyValue: '',
|
|
25
|
+
// operators: [
|
|
26
|
+
// {
|
|
27
|
+
// name: 'contains',
|
|
28
|
+
// fn: ({ value, filterValue, data }) => {
|
|
29
|
+
// console.log('fn');
|
|
30
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
31
|
+
// },
|
|
32
|
+
// },
|
|
33
|
+
// ],
|
|
34
|
+
// },
|
|
35
|
+
// };
|
|
20
36
|
const defaultOptions = {
|
|
37
|
+
//filterTypes: defaultfilterTypes,
|
|
38
|
+
remoteFilter: false,
|
|
39
|
+
remoteSort: false,
|
|
21
40
|
rowReorderColumn: false,
|
|
22
41
|
resizable: true,
|
|
23
42
|
rowIndexColumn: true
|
|
@@ -42,18 +61,48 @@ function AzGrid(props) {
|
|
|
42
61
|
/* -------------------------------------------------------------------------- */
|
|
43
62
|
/* Row changes */
|
|
44
63
|
/* -------------------------------------------------------------------------- */
|
|
64
|
+
const cached_data = _react.default.useRef();
|
|
65
|
+
const last_cache_info = _react.default.useRef();
|
|
45
66
|
const dataSource = _react.default.useCallback(async dt => {
|
|
46
67
|
let result_data = undefined;
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
let isUsingCache = false;
|
|
69
|
+
//console.log(dt);
|
|
70
|
+
const cacheInfo = {
|
|
71
|
+
ds: props.dataSource,
|
|
72
|
+
skip: dt.skip,
|
|
73
|
+
limit: dt.limit
|
|
74
|
+
};
|
|
75
|
+
//check if we can used cached data
|
|
76
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
77
|
+
if (!(0, _object.object_equals)(last_cache_info.current, cacheInfo)) {
|
|
78
|
+
//console.log('invalid cache', cacheInfo);
|
|
79
|
+
cached_data.current = undefined;
|
|
80
|
+
last_cache_info.current = cacheInfo;
|
|
81
|
+
}
|
|
82
|
+
if (cached_data.current) {
|
|
83
|
+
//cache is valid, use the cache
|
|
84
|
+
//console.log('use cache', cached_data.current);
|
|
85
|
+
isUsingCache = true;
|
|
86
|
+
result_data = cached_data.current;
|
|
87
|
+
} else {
|
|
88
|
+
//console.log('use ds');
|
|
89
|
+
//cache is invalid, use the datasource again
|
|
90
|
+
isUsingCache = false;
|
|
91
|
+
if (typeof props.dataSource === 'function') {
|
|
92
|
+
result_data = await props.dataSource(dt);
|
|
93
|
+
} else result_data = props.dataSource;
|
|
49
94
|
}
|
|
95
|
+
//making sure the datasource is a valid object :
|
|
50
96
|
if (!result_data) result_data = [];
|
|
51
97
|
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
52
98
|
data: result_data
|
|
53
99
|
};
|
|
54
100
|
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
55
|
-
|
|
101
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
102
|
+
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
56
103
|
if (!result_data.count) result_data.count = result_data.data.length;
|
|
104
|
+
//update cache
|
|
105
|
+
cached_data.current = result_data;
|
|
57
106
|
return result_data;
|
|
58
107
|
}, [props.dataSource]);
|
|
59
108
|
return _react.default.createElement(DataGrid, {
|
|
@@ -72,6 +121,7 @@ function DataGrid(props) {
|
|
|
72
121
|
contextMenuItems
|
|
73
122
|
} = props;
|
|
74
123
|
/* -------------------------------------------------------------------------- */
|
|
124
|
+
const gridRef = _react.default.useRef(null);
|
|
75
125
|
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
76
126
|
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
77
127
|
/* -------------------------------------------------------------------------- */
|
|
@@ -145,6 +195,7 @@ function DataGrid(props) {
|
|
|
145
195
|
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
146
196
|
...static_gridOptions,
|
|
147
197
|
...dynamic_gridOptions,
|
|
198
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
148
199
|
className: 'azgrid-filler',
|
|
149
200
|
columns: columns,
|
|
150
201
|
dataSource: dataSource
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azrico/reactgrid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "React Datagrid",
|
|
6
6
|
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@azrico/controls": "1.3.0",
|
|
33
|
+
"@azrico/object": "^1.3.1",
|
|
33
34
|
"@emotion/react": "^11.9.3",
|
|
34
35
|
"@emotion/styled": "^11.9.3",
|
|
35
36
|
"@inovua/reactdatagrid-enterprise": "^5.8.0",
|
package/src/example.tsx
CHANGED
|
@@ -5,11 +5,12 @@ import { LooseColumnDefinition } from './views/DataGrid';
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import ReactDOM from 'react-dom/client';
|
|
7
7
|
|
|
8
|
-
const columns
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const columns = [
|
|
9
|
+
{
|
|
10
|
+
name: 'name',
|
|
11
|
+
title: 'Category',
|
|
12
|
+
defaultFlex: 1,
|
|
13
|
+
},
|
|
13
14
|
];
|
|
14
15
|
const leftColumns = ['username', 'row'];
|
|
15
16
|
const customColumns = [
|
|
@@ -20,18 +21,26 @@ const customColumns = [
|
|
|
20
21
|
},
|
|
21
22
|
},
|
|
22
23
|
];
|
|
24
|
+
const filterValue = [
|
|
25
|
+
{
|
|
26
|
+
name: 'name',
|
|
27
|
+
operator: 'contains',
|
|
28
|
+
type: 'string',
|
|
29
|
+
value: '',
|
|
30
|
+
},
|
|
31
|
+
];
|
|
23
32
|
|
|
24
33
|
const contextMenuItems = ['test'];
|
|
25
34
|
function getData() {
|
|
26
35
|
const fd: any[] = [];
|
|
27
|
-
for (let index = 0; index <
|
|
28
|
-
fd.push({ __table_id: String(index),
|
|
36
|
+
for (let index = 0; index < 200; index++) {
|
|
37
|
+
fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
|
|
29
38
|
if (index % 5 == 0) {
|
|
30
39
|
const sub_selfid = 's' + index;
|
|
31
40
|
fd.push({
|
|
32
41
|
__table_id: sub_selfid,
|
|
33
42
|
__parent__table_id: String(index),
|
|
34
|
-
|
|
43
|
+
name: 'sub-' + index,
|
|
35
44
|
age: 20,
|
|
36
45
|
});
|
|
37
46
|
if (index % 2 == 0) {
|
|
@@ -39,7 +48,7 @@ function getData() {
|
|
|
39
48
|
fd.push({
|
|
40
49
|
__table_id: sub2_selfid,
|
|
41
50
|
__parent__table_id: sub_selfid,
|
|
42
|
-
|
|
51
|
+
name: 'sub2-' + index,
|
|
43
52
|
age: 20,
|
|
44
53
|
});
|
|
45
54
|
}
|
|
@@ -47,7 +56,7 @@ function getData() {
|
|
|
47
56
|
}
|
|
48
57
|
return fd;
|
|
49
58
|
}
|
|
50
|
-
|
|
59
|
+
//TODO REMOTE FILTER OFF ?
|
|
51
60
|
export function ExampleGrid() {
|
|
52
61
|
const [selected, setSelected] = React.useState(null);
|
|
53
62
|
|
|
@@ -60,52 +69,34 @@ export function ExampleGrid() {
|
|
|
60
69
|
return await new Promise((resolve) => {
|
|
61
70
|
setTimeout(() => {
|
|
62
71
|
console.log('end loading');
|
|
63
|
-
resolve(
|
|
72
|
+
resolve(getData());
|
|
64
73
|
}, 1000);
|
|
65
74
|
});
|
|
66
75
|
}, []);
|
|
67
76
|
|
|
68
77
|
return (
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
allowChildRows
|
|
92
|
-
onSelectionChange={onSelectionChange}
|
|
93
|
-
selected={selected}
|
|
94
|
-
contextMenuItems={contextMenuItems}
|
|
95
|
-
customColumns={customColumns}
|
|
96
|
-
columns={columns}
|
|
97
|
-
leftColumns={leftColumns}
|
|
98
|
-
gridOptions={{
|
|
99
|
-
pagination: 'remote',
|
|
100
|
-
defaultLimit: 100,
|
|
101
|
-
limit: 100,
|
|
102
|
-
pageSizes: [100],
|
|
103
|
-
rowIndexColumn: true,
|
|
104
|
-
checkboxColumn: true,
|
|
105
|
-
}}
|
|
106
|
-
dataSource={dataSource}
|
|
107
|
-
/>
|
|
108
|
-
</div>
|
|
78
|
+
<AzGrid
|
|
79
|
+
dark
|
|
80
|
+
allowChildRows
|
|
81
|
+
// onSelectionChange={onSelectionChange}
|
|
82
|
+
// selected={selected}
|
|
83
|
+
contextMenuItems={contextMenuItems}
|
|
84
|
+
customColumns={customColumns}
|
|
85
|
+
columns={columns}
|
|
86
|
+
leftColumns={leftColumns}
|
|
87
|
+
gridOptions={{
|
|
88
|
+
defaultFilterValue: filterValue,
|
|
89
|
+
remoteFilter: false,
|
|
90
|
+
multiSelect: true,
|
|
91
|
+
pagination: 'local',
|
|
92
|
+
defaultLimit: 100,
|
|
93
|
+
limit: 100,
|
|
94
|
+
pageSizes: [100],
|
|
95
|
+
rowIndexColumn: true,
|
|
96
|
+
checkboxColumn: true,
|
|
97
|
+
}}
|
|
98
|
+
dataSource={dataSource}
|
|
99
|
+
/>
|
|
109
100
|
);
|
|
110
101
|
}
|
|
111
102
|
export default ExampleGrid;
|
package/src/index.tsx
CHANGED
|
@@ -7,5 +7,5 @@ import React from 'react';
|
|
|
7
7
|
import ReactDOM from 'react-dom/client';
|
|
8
8
|
export default AzGrid;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
11
|
+
root.render(<ExampleGrid />);
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
TypeColumn,
|
|
10
10
|
TypeDataGridProps,
|
|
11
11
|
TypeDataSource,
|
|
12
|
+
TypeFilterTypes,
|
|
12
13
|
TypeRowDetailsInfo,
|
|
13
14
|
TypeRowProps,
|
|
14
15
|
TypeRowSelection,
|
|
@@ -19,6 +20,7 @@ import { ContextMenu } from '@azrico/controls';
|
|
|
19
20
|
import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
|
|
20
21
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
21
22
|
import clsx from 'clsx';
|
|
23
|
+
import { object_equals } from '@azrico/object';
|
|
22
24
|
import { useResizeDetector } from 'react-resize-detector';
|
|
23
25
|
|
|
24
26
|
/* -------------------------------------------------------------------------- */
|
|
@@ -33,6 +35,7 @@ export type RowDefinition = any;
|
|
|
33
35
|
export type RowProps = TypeRowProps;
|
|
34
36
|
export type RowSelectionValue = TypeRowSelection;
|
|
35
37
|
export type DataRowDefinition = any;
|
|
38
|
+
export type FilterTypes = TypeFilterTypes;
|
|
36
39
|
export type DataSourceDefinition = TypeDataSource;
|
|
37
40
|
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
38
41
|
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
@@ -99,10 +102,28 @@ type DataGridProps = ModifyFields<
|
|
|
99
102
|
}
|
|
100
103
|
>;
|
|
101
104
|
/* -------------------------------------------------------------------------- */
|
|
105
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
106
|
+
// string: {
|
|
107
|
+
// type: 'string',
|
|
108
|
+
// emptyValue: '',
|
|
109
|
+
// operators: [
|
|
110
|
+
// {
|
|
111
|
+
// name: 'contains',
|
|
112
|
+
// fn: ({ value, filterValue, data }) => {
|
|
113
|
+
// console.log('fn');
|
|
114
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
115
|
+
// },
|
|
116
|
+
// },
|
|
117
|
+
// ],
|
|
118
|
+
// },
|
|
119
|
+
// };
|
|
102
120
|
const defaultOptions: GridOptions = {
|
|
121
|
+
//filterTypes: defaultfilterTypes,
|
|
122
|
+
remoteFilter: false,
|
|
123
|
+
remoteSort: false,
|
|
124
|
+
|
|
103
125
|
rowReorderColumn: false,
|
|
104
126
|
resizable: true,
|
|
105
|
-
|
|
106
127
|
rowIndexColumn: true,
|
|
107
128
|
};
|
|
108
129
|
const forcedOptions: GridOptions = {
|
|
@@ -132,22 +153,57 @@ export function AzGrid(props: AzGridProps) {
|
|
|
132
153
|
/* -------------------------------------------------------------------------- */
|
|
133
154
|
/* Row changes */
|
|
134
155
|
/* -------------------------------------------------------------------------- */
|
|
156
|
+
|
|
157
|
+
const cached_data = React.useRef<any>();
|
|
158
|
+
const last_cache_info = React.useRef<any>();
|
|
159
|
+
|
|
135
160
|
const dataSource = React.useCallback(
|
|
136
161
|
async (dt) => {
|
|
137
162
|
let result_data: any = undefined;
|
|
138
|
-
|
|
139
|
-
|
|
163
|
+
|
|
164
|
+
let isUsingCache = false;
|
|
165
|
+
//console.log(dt);
|
|
166
|
+
const cacheInfo = { ds: props.dataSource, skip: dt.skip, limit: dt.limit };
|
|
167
|
+
//check if we can used cached data
|
|
168
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
169
|
+
if (!object_equals(last_cache_info.current, cacheInfo)) {
|
|
170
|
+
//console.log('invalid cache', cacheInfo);
|
|
171
|
+
cached_data.current = undefined;
|
|
172
|
+
last_cache_info.current = cacheInfo;
|
|
140
173
|
}
|
|
141
|
-
if (!result_data) result_data = [];
|
|
142
174
|
|
|
175
|
+
if (cached_data.current) {
|
|
176
|
+
//cache is valid, use the cache
|
|
177
|
+
//console.log('use cache', cached_data.current);
|
|
178
|
+
|
|
179
|
+
isUsingCache = true;
|
|
180
|
+
result_data = cached_data.current;
|
|
181
|
+
} else {
|
|
182
|
+
//console.log('use ds');
|
|
183
|
+
|
|
184
|
+
//cache is invalid, use the datasource again
|
|
185
|
+
isUsingCache = false;
|
|
186
|
+
|
|
187
|
+
if (typeof props.dataSource === 'function') {
|
|
188
|
+
result_data = await props.dataSource(dt);
|
|
189
|
+
} else result_data = props.dataSource;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//making sure the datasource is a valid object :
|
|
193
|
+
if (!result_data) result_data = [];
|
|
143
194
|
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
144
195
|
result_data = { data: result_data };
|
|
145
196
|
|
|
146
197
|
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
147
|
-
|
|
198
|
+
|
|
199
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
200
|
+
if (!isUsingCache && props.allowChildRows)
|
|
148
201
|
result_data.data = fix_parent_child_relations(result_data.data);
|
|
202
|
+
|
|
149
203
|
if (!result_data.count) result_data.count = (result_data.data as Array<any>).length;
|
|
150
204
|
|
|
205
|
+
//update cache
|
|
206
|
+
cached_data.current = result_data;
|
|
151
207
|
return result_data;
|
|
152
208
|
},
|
|
153
209
|
[props.dataSource]
|
|
@@ -167,6 +223,7 @@ function DataGrid(props: DataGridProps) {
|
|
|
167
223
|
const { columns, dataSource, dark, contextMenuItems } = props;
|
|
168
224
|
|
|
169
225
|
/* -------------------------------------------------------------------------- */
|
|
226
|
+
const gridRef = React.useRef<any>(null);
|
|
170
227
|
|
|
171
228
|
const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
|
|
172
229
|
const [menuRow, set_menuRow] = React.useState<any>(null);
|
|
@@ -245,6 +302,7 @@ function DataGrid(props: DataGridProps) {
|
|
|
245
302
|
<ReactDataGrid
|
|
246
303
|
{...static_gridOptions}
|
|
247
304
|
{...dynamic_gridOptions}
|
|
305
|
+
handle={(ref) => (gridRef.current = ref ? ref.current : null)}
|
|
248
306
|
className={'azgrid-filler'}
|
|
249
307
|
columns={columns}
|
|
250
308
|
dataSource={dataSource}
|