@azrico/reactgrid 1.2.7 → 1.2.11
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 +32 -3
- package/dist/src/example.js +12 -20
- package/dist/src/func/func_grid.js +6 -2
- package/dist/src/views/DataGrid.d.ts +1 -1
- package/dist/src/views/DataGrid.js +2 -4
- package/package.json +1 -1
- package/public/manifest.json +9 -9
- package/src/example.tsx +13 -19
- package/src/func/func_grid.ts +289 -288
- package/src/views/DataGrid.tsx +5 -5
- package/src/views/index.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
### 1.2.6 (2023-02-26)
|
|
5
|
+
### 1.2.11 (2023-03-31)
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
### Features
|
|
@@ -13,6 +11,7 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
13
11
|
* added inovua grid ([a178208](https://github.com/Azrideus/azrico-reactgrid/commit/a178208975212d16ce9feff359b09a6d8926b54d))
|
|
14
12
|
* added onLimitChange ([4b16681](https://github.com/Azrideus/azrico-reactgrid/commit/4b1668194776ebec51cdf9af0969132d5883d79a))
|
|
15
13
|
* added skip and limit values ([87a975c](https://github.com/Azrideus/azrico-reactgrid/commit/87a975cad9803b4d41d770c0758d6b4d09946a53))
|
|
14
|
+
* editable can be a function ([6ea857e](https://github.com/Azrideus/azrico-reactgrid/commit/6ea857e4f403d2a334dc5e74065f6b8033277ca4))
|
|
16
15
|
* fixed dataSource ([ce5a4fe](https://github.com/Azrideus/azrico-reactgrid/commit/ce5a4fe09809aeddeeb0305d48b5294b1e9654b2))
|
|
17
16
|
|
|
18
17
|
|
|
@@ -25,3 +24,33 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
25
24
|
* fixed package for publish ([95b8f46](https://github.com/Azrideus/azrico-reactgrid/commit/95b8f46e672174928aa4d8cd6c4924553eb025e5))
|
|
26
25
|
* no null rows ([e85511b](https://github.com/Azrideus/azrico-reactgrid/commit/e85511beb98c884a3820dfae7c2c57891910b6d1))
|
|
27
26
|
* removed extra styles from maincode ([7ee097e](https://github.com/Azrideus/azrico-reactgrid/commit/7ee097e4b7db1209490ce29bdb25fc605dfa7db3))
|
|
27
|
+
|
|
28
|
+
### [1.2.10](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.9...v1.2.10) (2023-03-05)
|
|
29
|
+
|
|
30
|
+
### [1.2.9](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.8...v1.2.9) (2023-02-26)
|
|
31
|
+
|
|
32
|
+
### [1.2.8](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.7...v1.2.8) (2023-02-26)
|
|
33
|
+
|
|
34
|
+
### [1.2.7](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.6...v1.2.7) (2023-02-26)
|
|
35
|
+
|
|
36
|
+
### 1.2.6 (2023-02-26)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* added datasource Support ([4270ac1](https://github.com/Azrideus/azrico-reactgrid/commit/4270ac19623ef4c7404f0475825647c63ca98ffb))
|
|
42
|
+
* added inovua grid ([a178208](https://github.com/Azrideus/azrico-reactgrid/commit/a178208975212d16ce9feff359b09a6d8926b54d))
|
|
43
|
+
* added onLimitChange ([4b16681](https://github.com/Azrideus/azrico-reactgrid/commit/4b1668194776ebec51cdf9af0969132d5883d79a))
|
|
44
|
+
* added skip and limit values ([87a975c](https://github.com/Azrideus/azrico-reactgrid/commit/87a975cad9803b4d41d770c0758d6b4d09946a53))
|
|
45
|
+
* fixed dataSource ([ce5a4fe](https://github.com/Azrideus/azrico-reactgrid/commit/ce5a4fe09809aeddeeb0305d48b5294b1e9654b2))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* added get_col_name ([c7ff2da](https://github.com/Azrideus/azrico-reactgrid/commit/c7ff2daab8bf2ddf3c5fcbe6b47c7876d9ed9f88))
|
|
51
|
+
* added support for promise DS ([b684c26](https://github.com/Azrideus/azrico-reactgrid/commit/b684c2635d59f5d5dde129ed6425ce30abbeebed))
|
|
52
|
+
* coyp styles to dist ([23694f2](https://github.com/Azrideus/azrico-reactgrid/commit/23694f23634eb0b4038f399b1b2cd5c57992b64b))
|
|
53
|
+
* fixed fix_parent_child_relations ([f165179](https://github.com/Azrideus/azrico-reactgrid/commit/f1651797e2adfc2dfbe1905b8c858b150c842dfa))
|
|
54
|
+
* fixed package for publish ([95b8f46](https://github.com/Azrideus/azrico-reactgrid/commit/95b8f46e672174928aa4d8cd6c4924553eb025e5))
|
|
55
|
+
* no null rows ([e85511b](https://github.com/Azrideus/azrico-reactgrid/commit/e85511beb98c884a3820dfae7c2c57891910b6d1))
|
|
56
|
+
* removed extra styles from maincode ([7ee097e](https://github.com/Azrideus/azrico-reactgrid/commit/7ee097e4b7db1209490ce29bdb25fc605dfa7db3))
|
package/dist/src/example.js
CHANGED
|
@@ -56,27 +56,19 @@ function getData(delta, max = 200) {
|
|
|
56
56
|
currentObject[key] = delta[index][key];
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
const childrows = [];
|
|
60
|
+
if (index % 5 == 0) {
|
|
61
|
+
const sub_selfid = 's' + index;
|
|
62
|
+
childrows.push({
|
|
63
|
+
__table_id: sub_selfid,
|
|
64
|
+
__parent__table_id: String(index),
|
|
65
|
+
name: 'sub-' + index,
|
|
66
|
+
age: 20
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
currentObject['__children'] = childrows;
|
|
59
70
|
fd.push(currentObject);
|
|
60
|
-
//if (index % 5 == 0) {
|
|
61
|
-
// const sub_selfid = 's' + index;
|
|
62
|
-
// fd.push({
|
|
63
|
-
// __table_id: sub_selfid,
|
|
64
|
-
// __parent__table_id: String(index),
|
|
65
|
-
// name: 'sub-' + index,
|
|
66
|
-
// age: 20,
|
|
67
|
-
// });
|
|
68
|
-
// if (index % 2 == 0) {
|
|
69
|
-
// const sub2_selfid = 'ss' + index;
|
|
70
|
-
// fd.push({
|
|
71
|
-
// __table_id: sub2_selfid,
|
|
72
|
-
// __parent__table_id: sub_selfid,
|
|
73
|
-
// name: 'sub2-' + index,
|
|
74
|
-
// age: 20,
|
|
75
|
-
// });
|
|
76
|
-
// }
|
|
77
|
-
//}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
return fd;
|
|
81
73
|
}
|
|
82
74
|
function ExampleGrid() {
|
|
@@ -141,7 +133,7 @@ function ExampleGrid() {
|
|
|
141
133
|
details_columns: columns,
|
|
142
134
|
onRowClick: onRowClick,
|
|
143
135
|
onRowDoubleClick: onRowDoubleClick,
|
|
144
|
-
|
|
136
|
+
allowChildRows: true,
|
|
145
137
|
// onSelectionChange={onSelectionChange}
|
|
146
138
|
// selected={selected}
|
|
147
139
|
contextMenuItems: contextMenuItems,
|
|
@@ -14,6 +14,7 @@ exports.validateCache = validateCache;
|
|
|
14
14
|
var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
|
|
15
15
|
var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
|
|
16
16
|
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
17
|
+
var _func_child = require("./func_child");
|
|
17
18
|
var _object = require("@azrico/object");
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
20
|
const defaultColumnOptions = {
|
|
@@ -53,9 +54,12 @@ async function ApplyDataSource(datasource, props) {
|
|
|
53
54
|
};
|
|
54
55
|
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
55
56
|
//no need to fix parent/child when using cache (it should be already fixed)
|
|
56
|
-
if (!isUsingCache && props.allowChildRows)
|
|
57
|
-
|
|
57
|
+
if (!isUsingCache && props.allowChildRows) {
|
|
58
|
+
result_data.data = (0, _func_child.fix_parent_child_relations)(result_data.data);
|
|
59
|
+
}
|
|
60
|
+
if (!result_data.count) {
|
|
58
61
|
result_data.count = result_data.data.length;
|
|
62
|
+
}
|
|
59
63
|
//update cache
|
|
60
64
|
props.cached_data.current = result_data;
|
|
61
65
|
return result_data;
|
|
@@ -61,9 +61,9 @@ export type AzGridProps = {
|
|
|
61
61
|
onSkipChange?: (v: number) => void;
|
|
62
62
|
skip?: number;
|
|
63
63
|
limit?: number;
|
|
64
|
+
editable?: boolean | ((editValue: any, cellProps: any) => boolean);
|
|
64
65
|
loading?: boolean;
|
|
65
66
|
dark?: boolean;
|
|
66
|
-
editable?: boolean;
|
|
67
67
|
delayedSize?: boolean;
|
|
68
68
|
allowChildRows?: boolean;
|
|
69
69
|
looseCacheCheck?: boolean;
|
|
@@ -28,9 +28,7 @@ const defaultOptions = {
|
|
|
28
28
|
resizable: true,
|
|
29
29
|
columnUserSelect: true,
|
|
30
30
|
rowIndexColumn: true,
|
|
31
|
-
rowHeight: 35
|
|
32
|
-
maxRowHeight: 40,
|
|
33
|
-
minRowHeight: 30
|
|
31
|
+
rowHeight: 35
|
|
34
32
|
};
|
|
35
33
|
const forcedOptions = {
|
|
36
34
|
idProperty: '__table_id',
|
|
@@ -168,7 +166,7 @@ function DataGridEventsWrapper(props) {
|
|
|
168
166
|
menuAnchorEl: menuAnchorEl,
|
|
169
167
|
set_menuAnchorEl: update_menuAnchorEl,
|
|
170
168
|
menuRow: menuRow,
|
|
171
|
-
|
|
169
|
+
items: props.contextMenuItems
|
|
172
170
|
});
|
|
173
171
|
if (props.details_dataSource) {
|
|
174
172
|
return _react.default.createElement(DataGridDetailsWrapper, {
|
package/package.json
CHANGED
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
|
+
}
|
package/src/example.tsx
CHANGED
|
@@ -45,25 +45,19 @@ function getData(delta: any, max = 200) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
const childrows: any[] = [];
|
|
49
|
+
if (index % 5 == 0) {
|
|
50
|
+
const sub_selfid = 's' + index;
|
|
51
|
+
childrows.push({
|
|
52
|
+
__table_id: sub_selfid,
|
|
53
|
+
__parent__table_id: String(index),
|
|
54
|
+
name: 'sub-' + index,
|
|
55
|
+
age: 20,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
currentObject['__children'] = childrows;
|
|
48
60
|
fd.push(currentObject);
|
|
49
|
-
//if (index % 5 == 0) {
|
|
50
|
-
// const sub_selfid = 's' + index;
|
|
51
|
-
// fd.push({
|
|
52
|
-
// __table_id: sub_selfid,
|
|
53
|
-
// __parent__table_id: String(index),
|
|
54
|
-
// name: 'sub-' + index,
|
|
55
|
-
// age: 20,
|
|
56
|
-
// });
|
|
57
|
-
// if (index % 2 == 0) {
|
|
58
|
-
// const sub2_selfid = 'ss' + index;
|
|
59
|
-
// fd.push({
|
|
60
|
-
// __table_id: sub2_selfid,
|
|
61
|
-
// __parent__table_id: sub_selfid,
|
|
62
|
-
// name: 'sub2-' + index,
|
|
63
|
-
// age: 20,
|
|
64
|
-
// });
|
|
65
|
-
// }
|
|
66
|
-
//}
|
|
67
61
|
}
|
|
68
62
|
return fd;
|
|
69
63
|
}
|
|
@@ -131,7 +125,7 @@ export function ExampleGrid() {
|
|
|
131
125
|
details_columns={columns}
|
|
132
126
|
onRowClick={onRowClick}
|
|
133
127
|
onRowDoubleClick={onRowDoubleClick}
|
|
134
|
-
|
|
128
|
+
allowChildRows
|
|
135
129
|
// onSelectionChange={onSelectionChange}
|
|
136
130
|
// selected={selected}
|
|
137
131
|
contextMenuItems={contextMenuItems}
|
package/src/func/func_grid.ts
CHANGED
|
@@ -1,288 +1,289 @@
|
|
|
1
|
-
import { ColumnDefinition, LooseColumnDefinition } from '../views/DataGrid';
|
|
2
|
-
|
|
3
|
-
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
|
|
4
|
-
import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
|
|
5
|
-
import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
|
|
6
|
-
import { fix_parent_child_relations } from './func_child';
|
|
7
|
-
import { object_equals } from '@azrico/object';
|
|
8
|
-
|
|
9
|
-
export type MakeWriteable<Type> = {
|
|
10
|
-
-readonly [Key in keyof Type]: Type[Key];
|
|
11
|
-
};
|
|
12
|
-
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
13
|
-
|
|
14
|
-
const defaultColumnOptions: ColumnDefinition = {
|
|
15
|
-
draggable: false,
|
|
16
|
-
lockable: false,
|
|
17
|
-
editable: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export async function ApplyDataSource(datasource, props) {
|
|
21
|
-
let result_data: any = undefined;
|
|
22
|
-
|
|
23
|
-
let isUsingCache = false;
|
|
24
|
-
|
|
25
|
-
const cacheInfo = { ds: datasource, skip: props.skip, limit: props.limit };
|
|
26
|
-
//check if we can used cached data
|
|
27
|
-
//if the datasource is changed since last render, we should invalidate cache
|
|
28
|
-
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
29
|
-
props.cached_data.current = undefined;
|
|
30
|
-
props.last_cache_info.current = cacheInfo;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (props.cached_data.current) {
|
|
34
|
-
//cache is valid, use the cache
|
|
35
|
-
isUsingCache = true;
|
|
36
|
-
result_data = props.cached_data.current;
|
|
37
|
-
} else {
|
|
38
|
-
//cache is invalid, use the datasource again
|
|
39
|
-
|
|
40
|
-
isUsingCache = false;
|
|
41
|
-
if (typeof datasource === 'function') {
|
|
42
|
-
result_data = await datasource(props);
|
|
43
|
-
} else result_data = datasource;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//making sure the datasource is a valid object :
|
|
47
|
-
if (!result_data) result_data = [];
|
|
48
|
-
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
49
|
-
result_data = { data: result_data };
|
|
50
|
-
|
|
51
|
-
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
52
|
-
|
|
53
|
-
//no need to fix parent/child when using cache (it should be already fixed)
|
|
54
|
-
if (!isUsingCache && props.allowChildRows)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
let
|
|
77
|
-
let
|
|
78
|
-
let
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
if (typeof r === '
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
...
|
|
97
|
-
...
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
case '
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
case '
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
case '
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (col.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
delete col.
|
|
211
|
-
delete col.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
*
|
|
241
|
-
* @
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
if (typeof obj
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
if (typeof obj
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
* @
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
if (typeof obj
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
*
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return
|
|
288
|
-
|
|
1
|
+
import { ColumnDefinition, LooseColumnDefinition } from '../views/DataGrid';
|
|
2
|
+
|
|
3
|
+
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
|
|
4
|
+
import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
|
|
5
|
+
import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
|
|
6
|
+
import { fix_parent_child_relations } from './func_child';
|
|
7
|
+
import { object_equals } from '@azrico/object';
|
|
8
|
+
|
|
9
|
+
export type MakeWriteable<Type> = {
|
|
10
|
+
-readonly [Key in keyof Type]: Type[Key];
|
|
11
|
+
};
|
|
12
|
+
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
13
|
+
|
|
14
|
+
const defaultColumnOptions: ColumnDefinition = {
|
|
15
|
+
draggable: false,
|
|
16
|
+
lockable: false,
|
|
17
|
+
editable: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function ApplyDataSource(datasource, props) {
|
|
21
|
+
let result_data: any = undefined;
|
|
22
|
+
|
|
23
|
+
let isUsingCache = false;
|
|
24
|
+
|
|
25
|
+
const cacheInfo = { ds: datasource, skip: props.skip, limit: props.limit };
|
|
26
|
+
//check if we can used cached data
|
|
27
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
28
|
+
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
29
|
+
props.cached_data.current = undefined;
|
|
30
|
+
props.last_cache_info.current = cacheInfo;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (props.cached_data.current) {
|
|
34
|
+
//cache is valid, use the cache
|
|
35
|
+
isUsingCache = true;
|
|
36
|
+
result_data = props.cached_data.current;
|
|
37
|
+
} else {
|
|
38
|
+
//cache is invalid, use the datasource again
|
|
39
|
+
|
|
40
|
+
isUsingCache = false;
|
|
41
|
+
if (typeof datasource === 'function') {
|
|
42
|
+
result_data = await datasource(props);
|
|
43
|
+
} else result_data = datasource;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//making sure the datasource is a valid object :
|
|
47
|
+
if (!result_data) result_data = [];
|
|
48
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object')
|
|
49
|
+
result_data = { data: result_data };
|
|
50
|
+
|
|
51
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
52
|
+
|
|
53
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
54
|
+
if (!isUsingCache && props.allowChildRows) {
|
|
55
|
+
result_data.data = fix_parent_child_relations(result_data.data);
|
|
56
|
+
}
|
|
57
|
+
if (!result_data.count) {
|
|
58
|
+
result_data.count = (result_data.data as Array<any>).length;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//update cache
|
|
62
|
+
props.cached_data.current = result_data;
|
|
63
|
+
return result_data;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* merges together all different props for columns
|
|
67
|
+
* to build a single final column data array
|
|
68
|
+
* @param column_data
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
export function ApplyColumnData(column_data: any): ColumnDefinition[] {
|
|
72
|
+
const final_columns: MakeWriteable<LooseColumnDefinition>[] = [];
|
|
73
|
+
if (!column_data) column_data = {};
|
|
74
|
+
if (Array.isArray(column_data)) column_data = { columns: column_data };
|
|
75
|
+
let mcols = column_data.columns || [];
|
|
76
|
+
let mcolExts = column_data.columnExtensions || [];
|
|
77
|
+
let rightColumns = column_data.rightColumns || [];
|
|
78
|
+
let leftColumns = column_data.leftColumns || [];
|
|
79
|
+
let editableColumns = column_data.editableColumns || [];
|
|
80
|
+
let customColumns = column_data.customColumns || [];
|
|
81
|
+
|
|
82
|
+
if (!Array.isArray(mcols)) return [];
|
|
83
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
84
|
+
|
|
85
|
+
mcols
|
|
86
|
+
.map((r) => {
|
|
87
|
+
if (r == null) return null;
|
|
88
|
+
if (typeof r === 'string') return { field: r, header: r };
|
|
89
|
+
if (typeof r === 'object') {
|
|
90
|
+
let final_cl: MakeWriteable<ColumnDefinition> = {
|
|
91
|
+
name: get_col_name(r),
|
|
92
|
+
header: get_col_header(r),
|
|
93
|
+
width: r.width || undefined,
|
|
94
|
+
};
|
|
95
|
+
final_cl = {
|
|
96
|
+
...defaultColumnOptions,
|
|
97
|
+
...r,
|
|
98
|
+
...final_cl,
|
|
99
|
+
};
|
|
100
|
+
return final_cl;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
})
|
|
104
|
+
.forEach((r) => {
|
|
105
|
+
if (r != null) final_columns.push(r);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
109
|
+
if (mcolExts && Array.isArray(mcolExts))
|
|
110
|
+
for (let index = 0; index < mcolExts.length; index++) {
|
|
111
|
+
const ext = mcolExts[index];
|
|
112
|
+
const ext_cl = get_col_name(ext);
|
|
113
|
+
if (!ext_cl) {
|
|
114
|
+
console.warn('ColumnExtension must have a name');
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const mcol = final_columns.find((s) => get_col_name(s) === ext_cl);
|
|
118
|
+
if (mcol) {
|
|
119
|
+
for (const key in ext) {
|
|
120
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
127
|
+
if (Array.isArray(leftColumns)) {
|
|
128
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
129
|
+
const r = get_col_name(leftColumns[index]);
|
|
130
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
131
|
+
if (mcol) {
|
|
132
|
+
mcol.locked = 'start';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(rightColumns)) {
|
|
137
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
138
|
+
const r = get_col_name(rightColumns[index]);
|
|
139
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
140
|
+
if (mcol) {
|
|
141
|
+
mcol.locked = 'end';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
146
|
+
if (Array.isArray(editableColumns)) {
|
|
147
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
148
|
+
const r = get_col_name(editableColumns[index]);
|
|
149
|
+
const mcol = final_columns.find((s) => get_col_name(s) === r);
|
|
150
|
+
if (mcol) {
|
|
151
|
+
mcol.editable = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
156
|
+
const col = final_columns[index];
|
|
157
|
+
if (col.type) {
|
|
158
|
+
switch (col.type) {
|
|
159
|
+
case 'combo':
|
|
160
|
+
case 'select':
|
|
161
|
+
//@ts-ignore
|
|
162
|
+
col.editor = SelectEditor;
|
|
163
|
+
break;
|
|
164
|
+
case 'number':
|
|
165
|
+
case 'numberic':
|
|
166
|
+
//@ts-ignore
|
|
167
|
+
col.editor = NumericEditor;
|
|
168
|
+
break;
|
|
169
|
+
case 'truefalse':
|
|
170
|
+
case 'bool':
|
|
171
|
+
//@ts-ignore
|
|
172
|
+
col.editor = BoolEditor;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
if (col.editable != false) col.editable = true;
|
|
176
|
+
delete col.type;
|
|
177
|
+
}
|
|
178
|
+
//@ts-ignore
|
|
179
|
+
if (!col.editorProps) col.editorProps = {};
|
|
180
|
+
if (col.items) {
|
|
181
|
+
//@ts-ignore
|
|
182
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
183
|
+
//@ts-ignore
|
|
184
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
185
|
+
//@ts-ignore
|
|
186
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
187
|
+
|
|
188
|
+
delete col.items;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* -------------------------------------------------------------------------- */
|
|
193
|
+
if (Array.isArray(customColumns)) {
|
|
194
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
195
|
+
const r = customColumns[index];
|
|
196
|
+
const rn = get_col_name(r);
|
|
197
|
+
const mcol = final_columns.find((s) => get_col_name(s) === rn);
|
|
198
|
+
if (mcol) {
|
|
199
|
+
//@ts-ignore
|
|
200
|
+
mcol.render = r.render;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
206
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
207
|
+
const col = final_columns[index];
|
|
208
|
+
if (!col.name) {
|
|
209
|
+
col.name = get_col_name(col);
|
|
210
|
+
delete col.field;
|
|
211
|
+
delete col.key;
|
|
212
|
+
delete col.columnName;
|
|
213
|
+
|
|
214
|
+
if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/* -------------------------------------------------------------------------- */
|
|
218
|
+
//console.log(final_columns);
|
|
219
|
+
return final_columns;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function to_datasource(arr: any[], idProperty: string, valueAsID = true) {
|
|
223
|
+
const res: any[] = [];
|
|
224
|
+
let index = 0;
|
|
225
|
+
if (Array.isArray(arr)) {
|
|
226
|
+
arr.map((s: any) => {
|
|
227
|
+
let elem = {};
|
|
228
|
+
if (valueAsID) elem[idProperty] = String(s).toLowerCase();
|
|
229
|
+
else elem[idProperty] = '_cid_' + index;
|
|
230
|
+
if (typeof s === 'object') elem = { ...elem, ...s };
|
|
231
|
+
else elem['label'] = s;
|
|
232
|
+
res.push(elem);
|
|
233
|
+
index++;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return res;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Gets name of a column from its column object
|
|
241
|
+
* @param obj
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
export function get_col_name(obj: any): string {
|
|
245
|
+
if (!obj) return '';
|
|
246
|
+
if (typeof obj == 'string') return obj;
|
|
247
|
+
if (typeof obj != 'object') return '';
|
|
248
|
+
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Gets header of a column
|
|
252
|
+
* @param obj
|
|
253
|
+
* @returns
|
|
254
|
+
*/
|
|
255
|
+
export function get_col_header(obj: any): string {
|
|
256
|
+
if (!obj) return '';
|
|
257
|
+
if (typeof obj == 'string') return obj;
|
|
258
|
+
if (typeof obj != 'object') return '';
|
|
259
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Gets name of a column from its column object
|
|
263
|
+
* @param obj
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
export function get_row_id(obj: any): any {
|
|
267
|
+
if (!obj) return '-1';
|
|
268
|
+
if (typeof obj == 'string') return obj;
|
|
269
|
+
if (typeof obj != 'object') return '-1';
|
|
270
|
+
return obj.__table_id || obj.id || '-1';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Gets default activation key for grid plugin
|
|
275
|
+
* @returns
|
|
276
|
+
*/
|
|
277
|
+
export function get_default_key() {
|
|
278
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//check if two cache objects are the same
|
|
282
|
+
export function validateCache(current: any, old: any, looseCheck = false) {
|
|
283
|
+
if (!old || !object_equals(current, old)) return false;
|
|
284
|
+
|
|
285
|
+
if (looseCheck) return true;
|
|
286
|
+
|
|
287
|
+
if (current.ds != old.ds) return false;
|
|
288
|
+
return true;
|
|
289
|
+
}
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -104,10 +104,12 @@ export type AzGridProps = {
|
|
|
104
104
|
/* -------------------------------------------------------------------------- */
|
|
105
105
|
skip?: number;
|
|
106
106
|
limit?: number;
|
|
107
|
+
//
|
|
108
|
+
editable?: boolean | ((editValue: any, cellProps: any) => boolean);
|
|
109
|
+
|
|
107
110
|
//
|
|
108
111
|
loading?: boolean;
|
|
109
112
|
dark?: boolean;
|
|
110
|
-
editable?: boolean;
|
|
111
113
|
delayedSize?: boolean;
|
|
112
114
|
allowChildRows?: boolean;
|
|
113
115
|
looseCacheCheck?: boolean;
|
|
@@ -141,8 +143,6 @@ const defaultOptions: GridOptions = {
|
|
|
141
143
|
columnUserSelect: true,
|
|
142
144
|
rowIndexColumn: true,
|
|
143
145
|
rowHeight: 35,
|
|
144
|
-
maxRowHeight: 40,
|
|
145
|
-
minRowHeight: 30,
|
|
146
146
|
};
|
|
147
147
|
const forcedOptions: GridOptions = {
|
|
148
148
|
idProperty: '__table_id',
|
|
@@ -197,7 +197,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
197
197
|
const extra_ops: GridOptions = {
|
|
198
198
|
onSelectionChange: props.onSelectionChange,
|
|
199
199
|
licenseKey: licenseKey,
|
|
200
|
-
editable: props.editable,
|
|
200
|
+
editable: props.editable as any, //bug in types of the plugin
|
|
201
201
|
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
202
202
|
renderRowDetails: props.RowDetail,
|
|
203
203
|
theme: props.dark ? 'amber-dark' : 'default-light',
|
|
@@ -315,7 +315,7 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
315
315
|
menuAnchorEl={menuAnchorEl}
|
|
316
316
|
set_menuAnchorEl={update_menuAnchorEl}
|
|
317
317
|
menuRow={menuRow}
|
|
318
|
-
|
|
318
|
+
items={props.contextMenuItems as any}
|
|
319
319
|
/>
|
|
320
320
|
);
|
|
321
321
|
|
package/src/views/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './DataGrid';
|
|
2
|
-
|
|
3
|
-
import AzGrid from './DataGrid';
|
|
4
|
-
export default AzGrid;
|
|
1
|
+
export * from './DataGrid';
|
|
2
|
+
|
|
3
|
+
import AzGrid from './DataGrid';
|
|
4
|
+
export default AzGrid;
|