@azrico/reactgrid 1.2.2 → 1.2.3
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/index.js +21 -3
- package/dist/src/example.js +150 -113
- package/dist/src/func/helpers.js +80 -75
- package/dist/src/index.js +28 -9
- package/dist/src/themes/base_styles.css +30 -0
- package/dist/src/themes/grid.css +20 -0
- package/dist/src/views/DataGrid.d.ts +1 -1
- package/dist/src/views/DataGrid.js +469 -457
- package/dist/src/views/index.js +23 -3
- package/package.json +2 -2
- package/src/views/DataGrid.tsx +1 -1
|
@@ -1,481 +1,493 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AzGrid = AzGrid;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
exports.get_col_header = get_col_header;
|
|
9
|
+
exports.get_col_name = get_col_name;
|
|
10
|
+
require("@inovua/reactdatagrid-enterprise/index.css");
|
|
11
|
+
require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
|
|
12
|
+
require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
|
|
13
|
+
require("../themes/base_styles.css");
|
|
14
|
+
require("../themes/grid.css");
|
|
15
|
+
var _controls = require("@azrico/controls");
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _helpers = require("../func/helpers");
|
|
18
|
+
var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
|
|
19
|
+
var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
|
|
20
|
+
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
21
|
+
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
22
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
23
|
+
var _object = require("@azrico/object");
|
|
24
|
+
var _reactUseSize = require("react-use-size");
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
+
/* -------------------------------------------------------------------------- */
|
|
27
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
28
|
+
// string: {
|
|
29
|
+
// type: 'string',
|
|
30
|
+
// emptyValue: '',
|
|
31
|
+
// operators: [
|
|
32
|
+
// {
|
|
33
|
+
// name: 'contains',
|
|
34
|
+
// fn: ({ value, filterValue, data }) => {
|
|
35
|
+
// console.log('fn');
|
|
36
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
37
|
+
// },
|
|
38
|
+
// },
|
|
39
|
+
// ],
|
|
40
|
+
// },
|
|
41
|
+
// };
|
|
42
|
+
const defaultOptions = {
|
|
43
|
+
//filterTypes: defaultfilterTypes,
|
|
44
|
+
remoteFilter: false,
|
|
45
|
+
remoteSort: false,
|
|
46
|
+
editStartEvent: 'click',
|
|
47
|
+
rowReorderColumn: false,
|
|
48
|
+
resizable: true,
|
|
49
|
+
columnUserSelect: true,
|
|
50
|
+
rowIndexColumn: true,
|
|
51
|
+
rowHeight: 35,
|
|
52
|
+
maxRowHeight: 40,
|
|
53
|
+
minRowHeight: 30
|
|
54
|
+
};
|
|
55
|
+
const forcedOptions = {
|
|
56
|
+
idProperty: '__table_id',
|
|
57
|
+
nodesProperty: '__children'
|
|
58
|
+
};
|
|
59
|
+
const defaultColumnOptions = {
|
|
60
|
+
draggable: false,
|
|
61
|
+
lockable: false,
|
|
62
|
+
editable: false
|
|
63
|
+
};
|
|
64
|
+
const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
|
|
65
|
+
/* -------------------------------------------------------------------------- */
|
|
66
|
+
function AzGrid(props) {
|
|
67
|
+
/* -------------------------------------------------------------------------- */
|
|
68
|
+
/* Columns */
|
|
69
|
+
/* -------------------------------------------------------------------------- */
|
|
70
|
+
const cached_columns = _react.default.useMemo(() => {
|
|
71
|
+
return ApplyColumnData(props);
|
|
72
|
+
}, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
|
|
73
|
+
/* -------------------------------------------------------------------------- */
|
|
74
|
+
/* Row changes */
|
|
75
|
+
/* -------------------------------------------------------------------------- */
|
|
76
|
+
const cached_data = _react.default.useRef();
|
|
77
|
+
const last_cache_info = _react.default.useRef();
|
|
78
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
79
|
+
let result_data = undefined;
|
|
80
|
+
let isUsingCache = false;
|
|
81
|
+
const cacheInfo = {
|
|
82
|
+
ds: props.dataSource,
|
|
83
|
+
skip: dt.skip,
|
|
84
|
+
limit: dt.limit
|
|
85
|
+
};
|
|
86
|
+
//check if we can used cached data
|
|
87
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
88
|
+
if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
89
|
+
cached_data.current = undefined;
|
|
90
|
+
last_cache_info.current = cacheInfo;
|
|
91
|
+
}
|
|
92
|
+
if (cached_data.current) {
|
|
93
|
+
//cache is valid, use the cache
|
|
94
|
+
isUsingCache = true;
|
|
95
|
+
result_data = cached_data.current;
|
|
96
|
+
} else {
|
|
97
|
+
//cache is invalid, use the datasource again
|
|
98
|
+
isUsingCache = false;
|
|
99
|
+
if (typeof props.dataSource === 'function') {
|
|
100
|
+
result_data = await props.dataSource(dt);
|
|
101
|
+
} else result_data = props.dataSource;
|
|
102
|
+
}
|
|
103
|
+
//making sure the datasource is a valid object :
|
|
104
|
+
if (!result_data) result_data = [];
|
|
105
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
106
|
+
data: result_data
|
|
107
|
+
};
|
|
108
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
109
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
110
|
+
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
111
|
+
if (!result_data.count) result_data.count = result_data.data.length;
|
|
112
|
+
//update cache
|
|
113
|
+
cached_data.current = result_data;
|
|
114
|
+
return result_data;
|
|
115
|
+
}, [props.dataSource]);
|
|
116
|
+
const base_gridOptions = _react.default.useMemo(() => {
|
|
117
|
+
const firstcolumn = cached_columns[0];
|
|
118
|
+
const licenseKey = props.licenseKey || get_default_key();
|
|
119
|
+
const events = {
|
|
120
|
+
onSkipChange: props.onSkipChange,
|
|
121
|
+
onLimitChange: props.onLimitChange,
|
|
122
|
+
onEditComplete: props.onEditComplete
|
|
123
|
+
};
|
|
124
|
+
const extra_ops = {
|
|
125
|
+
onSelectionChange: props.onSelectionChange,
|
|
126
|
+
licenseKey: licenseKey,
|
|
127
|
+
editable: props.editable,
|
|
128
|
+
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
129
|
+
renderRowDetails: props.RowDetail,
|
|
130
|
+
theme: props.dark ? 'amber-dark' : 'default-light'
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
...defaultOptions,
|
|
134
|
+
...events,
|
|
135
|
+
...extra_ops
|
|
136
|
+
};
|
|
137
|
+
}, [cached_columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
|
|
138
|
+
const static_gridOptions = _react.default.useMemo(() => {
|
|
139
|
+
return {
|
|
140
|
+
...base_gridOptions,
|
|
141
|
+
...props.gridOptions,
|
|
142
|
+
...forcedOptions
|
|
143
|
+
};
|
|
144
|
+
}, [props.gridOptions, base_gridOptions, forcedOptions]);
|
|
145
|
+
const dynamic_gridOptions = _react.default.useMemo(() => {
|
|
146
|
+
const res = {};
|
|
147
|
+
dynamic_option_names.map(r => {
|
|
148
|
+
res[r] = props[r];
|
|
149
|
+
});
|
|
150
|
+
return res;
|
|
151
|
+
}, dynamic_option_names.map(r => props[r]));
|
|
152
|
+
return _react.default.createElement(DataGridEventsWrapper, {
|
|
153
|
+
...props,
|
|
154
|
+
static_gridOptions: static_gridOptions,
|
|
155
|
+
dynamic_gridOptions: dynamic_gridOptions,
|
|
156
|
+
columns: cached_columns,
|
|
157
|
+
dataSource: dataSource,
|
|
158
|
+
highlightedRow: props.highlightedRow
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/* -------------------------------------------------------------------------- */
|
|
152
162
|
/**
|
|
153
163
|
* Wrapper for menu events
|
|
154
164
|
* @param props
|
|
155
165
|
* @returns
|
|
156
|
-
*/
|
|
157
|
-
function DataGridEventsWrapper(props) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
166
|
+
*/
|
|
167
|
+
function DataGridEventsWrapper(props) {
|
|
168
|
+
/* -------------------------------------------------------------------------- */
|
|
169
|
+
const click_data = _react.default.useRef(null);
|
|
170
|
+
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
171
|
+
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
172
|
+
/* --------------------------------- events --------------------------------- */
|
|
173
|
+
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
174
|
+
if (_helpers.func_selection.has_selection()) return;
|
|
175
|
+
update_menuRow(rowProps.data);
|
|
176
|
+
update_menuAnchorEl(_helpers.func_selection.getVirtualElement(event.clientX, event.clientY));
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
}, []);
|
|
179
|
+
const onRowClick = _react.default.useCallback((rowProps, event) => {
|
|
180
|
+
const nowDate = Date.now();
|
|
181
|
+
const lastclick = click_data.current[get_row_id(rowProps)];
|
|
182
|
+
if (lastclick) {
|
|
183
|
+
const diffTime = Math.abs(nowDate - lastclick);
|
|
184
|
+
if (diffTime < 400) {
|
|
185
|
+
click_data.current[get_row_id(rowProps)] = null;
|
|
186
|
+
return props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
click_data.current[get_row_id(rowProps)] = nowDate;
|
|
190
|
+
return props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
|
|
191
|
+
}, [props.onRowClick, props.onRowDoubleClick]);
|
|
192
|
+
_react.default.useEffect(() => {
|
|
193
|
+
click_data.current = {};
|
|
194
|
+
}, [props.dataSource]);
|
|
195
|
+
/* ------------------------------- ContextMenu ------------------------------ */
|
|
196
|
+
const update_menuAnchorEl = _react.default.useCallback(el => {
|
|
197
|
+
if (el) {
|
|
198
|
+
set_menuAnchorEl(el);
|
|
199
|
+
} else set_menuAnchorEl(null);
|
|
200
|
+
}, []);
|
|
201
|
+
const update_menuRow = _react.default.useCallback(r => {
|
|
202
|
+
if (r) {
|
|
203
|
+
set_menuRow(r);
|
|
204
|
+
} else set_menuRow(null);
|
|
205
|
+
}, []);
|
|
206
|
+
/**
|
|
207
|
+
* Merge click events into grid options
|
|
208
|
+
*/
|
|
209
|
+
const static_gridOptions = _react.default.useMemo(() => {
|
|
210
|
+
const events = {
|
|
211
|
+
onRowClick: onRowClick,
|
|
212
|
+
onRowContextMenu: onRowContextMenu
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
...props.static_gridOptions,
|
|
216
|
+
...events
|
|
217
|
+
};
|
|
218
|
+
}, [props.static_gridOptions, onRowClick]);
|
|
219
|
+
return _react.default.createElement(DataGridSizeWrapper, {
|
|
220
|
+
...props,
|
|
221
|
+
static_gridOptions: static_gridOptions
|
|
222
|
+
}, _react.default.createElement(_controls.ContextMenu, {
|
|
223
|
+
menuAnchorEl: menuAnchorEl,
|
|
224
|
+
set_menuAnchorEl: update_menuAnchorEl,
|
|
225
|
+
menuRow: menuRow,
|
|
226
|
+
items: props.contextMenuItems
|
|
227
|
+
}), props.children);
|
|
228
|
+
}
|
|
229
|
+
function DataGridSizeWrapper(props) {
|
|
230
|
+
// console.log(props);
|
|
231
|
+
if (props.delayedSize) {
|
|
232
|
+
return _react.default.createElement(DataGridDelayedSize, {
|
|
233
|
+
...props
|
|
234
|
+
});
|
|
235
|
+
} else {
|
|
236
|
+
return _react.default.createElement(DataGridFlexSize, {
|
|
237
|
+
...props
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function DataGridDelayedSize(props) {
|
|
242
|
+
const gridRef = _react.default.useRef(null);
|
|
243
|
+
const {
|
|
244
|
+
ref,
|
|
245
|
+
height,
|
|
246
|
+
width
|
|
247
|
+
} = (0, _reactUseSize.useComponentSize)();
|
|
248
|
+
return _react.default.createElement("div", {
|
|
249
|
+
ref: ref,
|
|
250
|
+
className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
|
|
251
|
+
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
252
|
+
...props.static_gridOptions,
|
|
253
|
+
...props.dynamic_gridOptions,
|
|
254
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
255
|
+
className: 'azgrid-delayedresize',
|
|
256
|
+
style: {
|
|
257
|
+
height: height,
|
|
258
|
+
width: width
|
|
259
|
+
},
|
|
260
|
+
columns: props.columns,
|
|
261
|
+
dataSource: props.dataSource
|
|
262
|
+
}), props.children);
|
|
263
|
+
}
|
|
264
|
+
function DataGridFlexSize(props) {
|
|
265
|
+
const gridRef = _react.default.useRef(null);
|
|
266
|
+
return _react.default.createElement("div", {
|
|
267
|
+
className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
|
|
268
|
+
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
269
|
+
...props.static_gridOptions,
|
|
270
|
+
...props.dynamic_gridOptions,
|
|
271
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
272
|
+
className: 'azgrid-filler',
|
|
273
|
+
columns: props.columns,
|
|
274
|
+
dataSource: props.dataSource
|
|
275
|
+
}), props.children);
|
|
276
|
+
}
|
|
277
|
+
/* -------------------------------------------------------------------------- */
|
|
278
|
+
/* -------------------------------------------------------------------------- */
|
|
279
|
+
/* -------------------------------------------------------------------------- */
|
|
280
|
+
/* -------------------------------------------------------------------------- */
|
|
245
281
|
/**
|
|
246
282
|
* merges together all different props for columns
|
|
247
283
|
* to build a single final column data array
|
|
248
284
|
* @param props
|
|
249
285
|
* @returns
|
|
250
|
-
*/
|
|
251
|
-
function ApplyColumnData(props) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
elem[idProperty] = String(s).toLowerCase();
|
|
409
|
-
else
|
|
410
|
-
elem[idProperty] = '_cid_' + index;
|
|
411
|
-
if (typeof s === 'object')
|
|
412
|
-
elem = { ...elem, ...s };
|
|
413
|
-
else
|
|
414
|
-
elem['label'] = s;
|
|
415
|
-
res.push(elem);
|
|
416
|
-
index++;
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
return res;
|
|
420
|
-
}
|
|
286
|
+
*/
|
|
287
|
+
function ApplyColumnData(props) {
|
|
288
|
+
const final_columns = [];
|
|
289
|
+
let mcols = props.columns || [];
|
|
290
|
+
let mcolExts = props.columnExtensions || [];
|
|
291
|
+
let rightColumns = props.rightColumns || [];
|
|
292
|
+
let leftColumns = props.leftColumns || [];
|
|
293
|
+
let editableColumns = props.editableColumns || [];
|
|
294
|
+
let customColumns = props.customColumns || [];
|
|
295
|
+
if (!Array.isArray(mcols)) return [];
|
|
296
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
297
|
+
mcols.map(r => {
|
|
298
|
+
if (r == null) return null;
|
|
299
|
+
if (typeof r === 'string') return {
|
|
300
|
+
field: r,
|
|
301
|
+
header: r
|
|
302
|
+
};
|
|
303
|
+
if (typeof r === 'object') {
|
|
304
|
+
let final_cl = {
|
|
305
|
+
name: get_col_name(r),
|
|
306
|
+
header: get_col_header(r),
|
|
307
|
+
width: r.width || undefined
|
|
308
|
+
};
|
|
309
|
+
final_cl = {
|
|
310
|
+
...defaultColumnOptions,
|
|
311
|
+
...r,
|
|
312
|
+
...final_cl
|
|
313
|
+
};
|
|
314
|
+
return final_cl;
|
|
315
|
+
}
|
|
316
|
+
return null;
|
|
317
|
+
}).forEach(r => {
|
|
318
|
+
if (r != null) final_columns.push(r);
|
|
319
|
+
});
|
|
320
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
321
|
+
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
322
|
+
const ext = mcolExts[index];
|
|
323
|
+
const ext_cl = get_col_name(ext);
|
|
324
|
+
if (!ext_cl) {
|
|
325
|
+
console.warn('ColumnExtension must have a name');
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
|
|
329
|
+
if (mcol) {
|
|
330
|
+
for (const key in ext) {
|
|
331
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
335
|
+
}
|
|
336
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
337
|
+
if (Array.isArray(leftColumns)) {
|
|
338
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
339
|
+
const r = get_col_name(leftColumns[index]);
|
|
340
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
341
|
+
if (mcol) {
|
|
342
|
+
mcol.locked = 'start';
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (Array.isArray(rightColumns)) {
|
|
347
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
348
|
+
const r = get_col_name(rightColumns[index]);
|
|
349
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
350
|
+
if (mcol) {
|
|
351
|
+
mcol.locked = 'end';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
356
|
+
if (Array.isArray(editableColumns)) {
|
|
357
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
358
|
+
const r = get_col_name(editableColumns[index]);
|
|
359
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
360
|
+
if (mcol) {
|
|
361
|
+
mcol.editable = true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
366
|
+
const col = final_columns[index];
|
|
367
|
+
if (col.type) {
|
|
368
|
+
switch (col.type) {
|
|
369
|
+
case 'combo':
|
|
370
|
+
case 'select':
|
|
371
|
+
//@ts-ignore
|
|
372
|
+
col.editor = _SelectEditor.default;
|
|
373
|
+
break;
|
|
374
|
+
case 'number':
|
|
375
|
+
case 'numberic':
|
|
376
|
+
//@ts-ignore
|
|
377
|
+
col.editor = _NumericEditor.default;
|
|
378
|
+
break;
|
|
379
|
+
case 'truefalse':
|
|
380
|
+
case 'bool':
|
|
381
|
+
//@ts-ignore
|
|
382
|
+
col.editor = _BoolEditor.default;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
if (col.editable != false) col.editable = true;
|
|
386
|
+
delete col.type;
|
|
387
|
+
}
|
|
388
|
+
//@ts-ignore
|
|
389
|
+
if (!col.editorProps) col.editorProps = {};
|
|
390
|
+
if (col.items) {
|
|
391
|
+
//@ts-ignore
|
|
392
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
393
|
+
//@ts-ignore
|
|
394
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
395
|
+
//@ts-ignore
|
|
396
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
397
|
+
delete col.items;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/* -------------------------------------------------------------------------- */
|
|
401
|
+
if (Array.isArray(customColumns)) {
|
|
402
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
403
|
+
const r = customColumns[index];
|
|
404
|
+
const rn = get_col_name(r);
|
|
405
|
+
const mcol = final_columns.find(s => get_col_name(s) === rn);
|
|
406
|
+
if (mcol) {
|
|
407
|
+
//@ts-ignore
|
|
408
|
+
mcol.render = r.render;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
413
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
414
|
+
const col = final_columns[index];
|
|
415
|
+
if (!col.name) {
|
|
416
|
+
col.name = get_col_name(col);
|
|
417
|
+
delete col.field;
|
|
418
|
+
delete col.key;
|
|
419
|
+
delete col.columnName;
|
|
420
|
+
if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/* -------------------------------------------------------------------------- */
|
|
424
|
+
//console.log(final_columns);
|
|
425
|
+
return final_columns;
|
|
426
|
+
}
|
|
427
|
+
function to_datasource(arr, idProperty, valueAsID = true) {
|
|
428
|
+
const res = [];
|
|
429
|
+
let index = 0;
|
|
430
|
+
if (Array.isArray(arr)) {
|
|
431
|
+
arr.map(s => {
|
|
432
|
+
let elem = {};
|
|
433
|
+
if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
|
|
434
|
+
if (typeof s === 'object') elem = {
|
|
435
|
+
...elem,
|
|
436
|
+
...s
|
|
437
|
+
};else elem['label'] = s;
|
|
438
|
+
res.push(elem);
|
|
439
|
+
index++;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
return res;
|
|
443
|
+
}
|
|
421
444
|
/**
|
|
422
445
|
* Gets name of a column from its column object
|
|
423
446
|
* @param obj
|
|
424
447
|
* @returns
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return '';
|
|
433
|
-
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
434
|
-
}
|
|
448
|
+
*/
|
|
449
|
+
function get_col_name(obj) {
|
|
450
|
+
if (!obj) return '';
|
|
451
|
+
if (typeof obj == 'string') return obj;
|
|
452
|
+
if (typeof obj != 'object') return '';
|
|
453
|
+
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
454
|
+
}
|
|
435
455
|
/**
|
|
436
456
|
* Gets header of a column
|
|
437
457
|
* @param obj
|
|
438
458
|
* @returns
|
|
439
|
-
*/
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return '';
|
|
447
|
-
return obj.header || obj.title || get_col_name(obj);
|
|
448
|
-
}
|
|
459
|
+
*/
|
|
460
|
+
function get_col_header(obj) {
|
|
461
|
+
if (!obj) return '';
|
|
462
|
+
if (typeof obj == 'string') return obj;
|
|
463
|
+
if (typeof obj != 'object') return '';
|
|
464
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
465
|
+
}
|
|
449
466
|
/**
|
|
450
467
|
* Gets name of a column from its column object
|
|
451
468
|
* @param obj
|
|
452
469
|
* @returns
|
|
453
|
-
*/
|
|
454
|
-
function get_row_id(obj) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return '-1';
|
|
461
|
-
return obj.__table_id || obj.id || '-1';
|
|
462
|
-
}
|
|
470
|
+
*/
|
|
471
|
+
function get_row_id(obj) {
|
|
472
|
+
if (!obj) return '-1';
|
|
473
|
+
if (typeof obj == 'string') return obj;
|
|
474
|
+
if (typeof obj != 'object') return '-1';
|
|
475
|
+
return obj.__table_id || obj.id || '-1';
|
|
476
|
+
}
|
|
463
477
|
/**
|
|
464
478
|
* Gets default activation key for grid plugin
|
|
465
479
|
* @returns
|
|
466
|
-
*/
|
|
467
|
-
function get_default_key() {
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
//check if two cache objects are the same
|
|
471
|
-
function validateCache(current, old, looseCheck = false) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
/* -------------------------------------------------------------------------- */
|
|
481
|
-
export default AzGrid;
|
|
480
|
+
*/
|
|
481
|
+
function get_default_key() {
|
|
482
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
483
|
+
}
|
|
484
|
+
//check if two cache objects are the same
|
|
485
|
+
function validateCache(current, old, looseCheck = false) {
|
|
486
|
+
if (!old || !(0, _object.object_equals)(current, old)) return false;
|
|
487
|
+
if (looseCheck) return true;
|
|
488
|
+
if (current.ds != old.ds) return false;
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
/* -------------------------------------------------------------------------- */
|
|
492
|
+
var _default = AzGrid;
|
|
493
|
+
exports.default = _default;
|