@azrico/reactgrid 1.0.22 → 1.1.0
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 +2 -2
- package/dist/src/views/DataGrid.d.ts +2 -1
- package/dist/src/views/DataGrid.js +51 -16
- package/package.json +1 -1
- package/src/example.tsx +42 -51
- package/src/index.tsx +2 -2
- package/src/views/DataGrid.tsx +62 -14
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 < 400; 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
|
@@ -19,6 +19,6 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
19
19
|
});
|
|
20
20
|
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
21
|
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
|
-
var _default = _DataGrid.default; //
|
|
23
|
-
//
|
|
22
|
+
var _default = _DataGrid.default; //const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
23
|
+
//root.render(<ExampleGrid />);
|
|
24
24
|
exports.default = _default;
|
|
@@ -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;
|
|
@@ -17,7 +17,25 @@ var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdata
|
|
|
17
17
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
/* -------------------------------------------------------------------------- */
|
|
20
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
21
|
+
// string: {
|
|
22
|
+
// type: 'string',
|
|
23
|
+
// emptyValue: '',
|
|
24
|
+
// operators: [
|
|
25
|
+
// {
|
|
26
|
+
// name: 'contains',
|
|
27
|
+
// fn: ({ value, filterValue, data }) => {
|
|
28
|
+
// console.log('fn');
|
|
29
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
30
|
+
// },
|
|
31
|
+
// },
|
|
32
|
+
// ],
|
|
33
|
+
// },
|
|
34
|
+
// };
|
|
20
35
|
const defaultOptions = {
|
|
36
|
+
//filterTypes: defaultfilterTypes,
|
|
37
|
+
remoteFilter: false,
|
|
38
|
+
remoteSort: false,
|
|
21
39
|
rowReorderColumn: false,
|
|
22
40
|
resizable: true,
|
|
23
41
|
rowIndexColumn: true
|
|
@@ -42,26 +60,41 @@ function AzGrid(props) {
|
|
|
42
60
|
/* -------------------------------------------------------------------------- */
|
|
43
61
|
/* Row changes */
|
|
44
62
|
/* -------------------------------------------------------------------------- */
|
|
63
|
+
const cached_data = _react.default.useRef();
|
|
64
|
+
const last_ds = _react.default.useRef();
|
|
45
65
|
const dataSource = _react.default.useCallback(async dt => {
|
|
46
|
-
let result_rows = [];
|
|
47
66
|
let result_data = undefined;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
let isUsingCache = false;
|
|
68
|
+
//check if we can used cached data
|
|
69
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
70
|
+
if (last_ds.current != props.dataSource) {
|
|
71
|
+
//console.log('invalid cache', last_ds.current, props.dataSource);
|
|
72
|
+
cached_data.current = undefined;
|
|
73
|
+
last_ds.current = props.dataSource;
|
|
55
74
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
if (cached_data.current) {
|
|
76
|
+
//cache is valid, use the cache
|
|
77
|
+
isUsingCache = true;
|
|
78
|
+
result_data = cached_data.current;
|
|
79
|
+
} else {
|
|
80
|
+
//cache is invalid, use the datasource again
|
|
81
|
+
isUsingCache = false;
|
|
82
|
+
if (typeof props.dataSource === 'function') {
|
|
83
|
+
result_data = await props.dataSource(dt);
|
|
84
|
+
} else result_data = props.dataSource;
|
|
63
85
|
}
|
|
64
|
-
|
|
86
|
+
//making sure the datasource is a valid object :
|
|
87
|
+
if (!result_data) result_data = [];
|
|
88
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
89
|
+
data: result_data
|
|
90
|
+
};
|
|
91
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
92
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
93
|
+
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
94
|
+
if (!result_data.count) result_data.count = result_data.data.length;
|
|
95
|
+
//update cache
|
|
96
|
+
cached_data.current = result_data;
|
|
97
|
+
return result_data;
|
|
65
98
|
}, [props.dataSource]);
|
|
66
99
|
return _react.default.createElement(DataGrid, {
|
|
67
100
|
...props,
|
|
@@ -79,6 +112,7 @@ function DataGrid(props) {
|
|
|
79
112
|
contextMenuItems
|
|
80
113
|
} = props;
|
|
81
114
|
/* -------------------------------------------------------------------------- */
|
|
115
|
+
const gridRef = _react.default.useRef(null);
|
|
82
116
|
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
83
117
|
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
84
118
|
/* -------------------------------------------------------------------------- */
|
|
@@ -152,6 +186,7 @@ function DataGrid(props) {
|
|
|
152
186
|
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
153
187
|
...static_gridOptions,
|
|
154
188
|
...dynamic_gridOptions,
|
|
189
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
155
190
|
className: 'azgrid-filler',
|
|
156
191
|
columns: columns,
|
|
157
192
|
dataSource: dataSource
|
package/package.json
CHANGED
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 < 400; 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,
|
|
@@ -33,6 +34,7 @@ export type RowDefinition = any;
|
|
|
33
34
|
export type RowProps = TypeRowProps;
|
|
34
35
|
export type RowSelectionValue = TypeRowSelection;
|
|
35
36
|
export type DataRowDefinition = any;
|
|
37
|
+
export type FilterTypes = TypeFilterTypes;
|
|
36
38
|
export type DataSourceDefinition = TypeDataSource;
|
|
37
39
|
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
38
40
|
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
@@ -99,10 +101,28 @@ type DataGridProps = ModifyFields<
|
|
|
99
101
|
}
|
|
100
102
|
>;
|
|
101
103
|
/* -------------------------------------------------------------------------- */
|
|
104
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
105
|
+
// string: {
|
|
106
|
+
// type: 'string',
|
|
107
|
+
// emptyValue: '',
|
|
108
|
+
// operators: [
|
|
109
|
+
// {
|
|
110
|
+
// name: 'contains',
|
|
111
|
+
// fn: ({ value, filterValue, data }) => {
|
|
112
|
+
// console.log('fn');
|
|
113
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
114
|
+
// },
|
|
115
|
+
// },
|
|
116
|
+
// ],
|
|
117
|
+
// },
|
|
118
|
+
// };
|
|
102
119
|
const defaultOptions: GridOptions = {
|
|
120
|
+
//filterTypes: defaultfilterTypes,
|
|
121
|
+
remoteFilter: false,
|
|
122
|
+
remoteSort: false,
|
|
123
|
+
|
|
103
124
|
rowReorderColumn: false,
|
|
104
125
|
resizable: true,
|
|
105
|
-
|
|
106
126
|
rowIndexColumn: true,
|
|
107
127
|
};
|
|
108
128
|
const forcedOptions: GridOptions = {
|
|
@@ -132,25 +152,51 @@ export function AzGrid(props: AzGridProps) {
|
|
|
132
152
|
/* -------------------------------------------------------------------------- */
|
|
133
153
|
/* Row changes */
|
|
134
154
|
/* -------------------------------------------------------------------------- */
|
|
155
|
+
|
|
156
|
+
const cached_data = React.useRef<any>();
|
|
157
|
+
const last_ds = React.useRef<any>();
|
|
135
158
|
const dataSource = React.useCallback(
|
|
136
159
|
async (dt) => {
|
|
137
|
-
let result_rows: any[] = [];
|
|
138
160
|
let result_data: any = undefined;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
161
|
+
|
|
162
|
+
let isUsingCache = false;
|
|
163
|
+
//check if we can used cached data
|
|
164
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
165
|
+
if (last_ds.current != props.dataSource) {
|
|
166
|
+
//console.log('invalid cache', last_ds.current, props.dataSource);
|
|
167
|
+
cached_data.current = undefined;
|
|
168
|
+
last_ds.current = props.dataSource;
|
|
146
169
|
}
|
|
147
|
-
if (!Array.isArray(result_rows)) result_rows = [result_rows];
|
|
148
|
-
if (props.allowChildRows) result_rows = fix_parent_child_relations(result_rows);
|
|
149
170
|
|
|
150
|
-
if (
|
|
151
|
-
|
|
171
|
+
if (cached_data.current) {
|
|
172
|
+
//cache is valid, use the cache
|
|
173
|
+
isUsingCache = true;
|
|
174
|
+
result_data = cached_data.current;
|
|
175
|
+
} else {
|
|
176
|
+
//cache is invalid, use the datasource again
|
|
177
|
+
isUsingCache = false;
|
|
178
|
+
|
|
179
|
+
if (typeof props.dataSource === 'function') {
|
|
180
|
+
result_data = await props.dataSource(dt);
|
|
181
|
+
} else result_data = props.dataSource;
|
|
152
182
|
}
|
|
153
|
-
|
|
183
|
+
|
|
184
|
+
//making sure the datasource is a valid object :
|
|
185
|
+
if (!result_data) result_data = [];
|
|
186
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
187
|
+
result_data = { data: result_data };
|
|
188
|
+
|
|
189
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
190
|
+
|
|
191
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
192
|
+
if (!isUsingCache && props.allowChildRows)
|
|
193
|
+
result_data.data = fix_parent_child_relations(result_data.data);
|
|
194
|
+
|
|
195
|
+
if (!result_data.count) result_data.count = (result_data.data as Array<any>).length;
|
|
196
|
+
|
|
197
|
+
//update cache
|
|
198
|
+
cached_data.current = result_data;
|
|
199
|
+
return result_data;
|
|
154
200
|
},
|
|
155
201
|
[props.dataSource]
|
|
156
202
|
);
|
|
@@ -169,6 +215,7 @@ function DataGrid(props: DataGridProps) {
|
|
|
169
215
|
const { columns, dataSource, dark, contextMenuItems } = props;
|
|
170
216
|
|
|
171
217
|
/* -------------------------------------------------------------------------- */
|
|
218
|
+
const gridRef = React.useRef<any>(null);
|
|
172
219
|
|
|
173
220
|
const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
|
|
174
221
|
const [menuRow, set_menuRow] = React.useState<any>(null);
|
|
@@ -247,6 +294,7 @@ function DataGrid(props: DataGridProps) {
|
|
|
247
294
|
<ReactDataGrid
|
|
248
295
|
{...static_gridOptions}
|
|
249
296
|
{...dynamic_gridOptions}
|
|
297
|
+
handle={(ref) => (gridRef.current = ref ? ref.current : null)}
|
|
250
298
|
className={'azgrid-filler'}
|
|
251
299
|
columns={columns}
|
|
252
300
|
dataSource={dataSource}
|