@azrico/reactgrid 1.2.13 → 1.2.14
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 +2 -0
- package/dist/index.js +3 -21
- package/dist/src/example.js +118 -161
- package/dist/src/func/func_child.js +81 -84
- package/dist/src/func/func_grid.js +271 -260
- package/dist/src/index.js +6 -25
- package/dist/src/views/DataGrid.d.ts +7 -1
- package/dist/src/views/DataGrid.js +223 -269
- package/dist/src/views/index.js +3 -23
- package/package.json +1 -1
- package/src/views/DataGrid.tsx +9 -1
- package/dist/src/themes/base_styles.css +0 -30
- package/dist/src/themes/grid.css +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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
|
+
### [1.2.14](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.13...v1.2.14) (2023-04-01)
|
|
6
|
+
|
|
5
7
|
### [1.2.13](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.12...v1.2.13) (2023-04-01)
|
|
6
8
|
|
|
7
9
|
### [1.2.12](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.11...v1.2.12) (2023-03-31)
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {};
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _src = require("./src");
|
|
9
|
-
Object.keys(_src).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
12
|
-
if (key in exports && exports[key] === _src[key]) return;
|
|
13
|
-
Object.defineProperty(exports, key, {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _src[key];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
var _default = _src.AzGrid;
|
|
21
|
-
exports.default = _default;
|
|
1
|
+
export * from './src';
|
|
2
|
+
import { AzGrid } from './src';
|
|
3
|
+
export default AzGrid;
|
package/dist/src/example.js
CHANGED
|
@@ -1,161 +1,118 @@
|
|
|
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
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
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
|
-
set_delayed_reload(true);
|
|
120
|
-
}, 2000);
|
|
121
|
-
}, []);
|
|
122
|
-
const customColumns = _react.default.useMemo(() => {
|
|
123
|
-
if (!delayed_reload) return [];
|
|
124
|
-
return [{
|
|
125
|
-
name: 'name',
|
|
126
|
-
render: r => r.value + '^'
|
|
127
|
-
}];
|
|
128
|
-
}, [delayed_reload]);
|
|
129
|
-
return _react.default.createElement(_DataGrid.default, {
|
|
130
|
-
dark: true,
|
|
131
|
-
delayedSize: true,
|
|
132
|
-
details_dataSource: details_dataSource,
|
|
133
|
-
details_columns: columns,
|
|
134
|
-
onRowClick: onRowClick,
|
|
135
|
-
onRowDoubleClick: onRowDoubleClick,
|
|
136
|
-
allowChildRows: true,
|
|
137
|
-
// onSelectionChange={onSelectionChange}
|
|
138
|
-
// selected={selected}
|
|
139
|
-
contextMenuItems: contextMenuItems,
|
|
140
|
-
customColumns: customColumns,
|
|
141
|
-
columns: columns,
|
|
142
|
-
editableColumns: editableColumns,
|
|
143
|
-
editable: true,
|
|
144
|
-
onEditComplete: onEditComplete,
|
|
145
|
-
// leftColumns={leftColumns}
|
|
146
|
-
gridOptions: {
|
|
147
|
-
// defaultFilterValue: filterValue,
|
|
148
|
-
// remoteFilter: false,
|
|
149
|
-
// multiSelect: true,
|
|
150
|
-
// pagination: 'local',
|
|
151
|
-
// defaultLimit: 100,
|
|
152
|
-
// limit: 100,
|
|
153
|
-
// pageSizes: [100],
|
|
154
|
-
// rowIndexColumn: true,
|
|
155
|
-
// checkboxColumn: true,
|
|
156
|
-
},
|
|
157
|
-
dataSource: dataSource
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
var _default = ExampleGrid;
|
|
161
|
-
exports.default = _default;
|
|
1
|
+
export * from './views/DataGrid';
|
|
2
|
+
import AzGrid from './views/DataGrid';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
const columns = [
|
|
5
|
+
{
|
|
6
|
+
name: 'name',
|
|
7
|
+
title: 'Name',
|
|
8
|
+
defaultFlex: 1,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'job',
|
|
12
|
+
title: 'Job',
|
|
13
|
+
type: 'combo',
|
|
14
|
+
items: ['None', 'Engineer', 'Doctor'],
|
|
15
|
+
defaultFlex: 1,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'age',
|
|
19
|
+
title: 'Age',
|
|
20
|
+
defaultFlex: 1,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
const editableColumns = ['job', 'age'];
|
|
24
|
+
const contextMenuItems = ['test'];
|
|
25
|
+
function getData(delta, max = 200) {
|
|
26
|
+
const fd = [];
|
|
27
|
+
console.log('Delta:', delta);
|
|
28
|
+
for (let index = 0; index < max; index++) {
|
|
29
|
+
const currentObject = {
|
|
30
|
+
__table_id: String(index),
|
|
31
|
+
name: 'user-' + index,
|
|
32
|
+
age: 20,
|
|
33
|
+
job: 'None',
|
|
34
|
+
};
|
|
35
|
+
if (delta[index] && typeof delta[index] === 'object') {
|
|
36
|
+
for (const key in delta[index]) {
|
|
37
|
+
currentObject[key] = delta[index][key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const childrows = [];
|
|
41
|
+
if (index % 5 == 0) {
|
|
42
|
+
const sub_selfid = 's' + index;
|
|
43
|
+
childrows.push({
|
|
44
|
+
__table_id: sub_selfid,
|
|
45
|
+
__parent__table_id: String(index),
|
|
46
|
+
name: 'sub-' + index,
|
|
47
|
+
age: 20,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
currentObject['__children'] = childrows;
|
|
51
|
+
fd.push(currentObject);
|
|
52
|
+
}
|
|
53
|
+
return fd;
|
|
54
|
+
}
|
|
55
|
+
export function ExampleGrid() {
|
|
56
|
+
const [ds_reset, set_ds_reset] = React.useState(0);
|
|
57
|
+
const [delta, set_delta] = React.useState({});
|
|
58
|
+
const [delayed_reload, set_delayed_reload] = React.useState(false);
|
|
59
|
+
const dataSource = React.useCallback(async (dt) => {
|
|
60
|
+
//console.log('Start loading');
|
|
61
|
+
return await new Promise((resolve) => {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
resolve(getData(delta));
|
|
64
|
+
}, 1000);
|
|
65
|
+
});
|
|
66
|
+
}, [ds_reset, delta]);
|
|
67
|
+
const details_dataSource = React.useCallback(async (dt) => {
|
|
68
|
+
//console.log('Start loading');
|
|
69
|
+
return await new Promise((resolve) => {
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
resolve(getData(delta, 5));
|
|
72
|
+
}, 1000);
|
|
73
|
+
});
|
|
74
|
+
}, [ds_reset, delta]);
|
|
75
|
+
function onEditComplete(params) {
|
|
76
|
+
const { value, columnId, rowId, ...rest } = params;
|
|
77
|
+
let new_rd = delta[rowId];
|
|
78
|
+
if (!new_rd)
|
|
79
|
+
new_rd = {};
|
|
80
|
+
new_rd[columnId] = value;
|
|
81
|
+
set_delta((d) => {
|
|
82
|
+
return { ...d, [rowId]: new_rd };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const onRowDoubleClick = React.useCallback((index, rowdata) => {
|
|
86
|
+
console.log('dbl', rowdata?.data || rowdata);
|
|
87
|
+
}, []);
|
|
88
|
+
const onRowClick = React.useCallback((index, rowdata) => {
|
|
89
|
+
//console.log(rowdata?.data || rowdata);
|
|
90
|
+
}, []);
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
set_delayed_reload(true);
|
|
94
|
+
}, 2000);
|
|
95
|
+
}, []);
|
|
96
|
+
const customColumns = React.useMemo(() => {
|
|
97
|
+
if (!delayed_reload)
|
|
98
|
+
return [];
|
|
99
|
+
return [{ name: 'name', render: (r) => r.value + '^' }];
|
|
100
|
+
}, [delayed_reload]);
|
|
101
|
+
return (React.createElement(AzGrid, { dark: true, delayedSize: true, details_dataSource: details_dataSource, details_columns: columns, onRowClick: onRowClick, onRowDoubleClick: onRowDoubleClick, allowChildRows: true,
|
|
102
|
+
// onSelectionChange={onSelectionChange}
|
|
103
|
+
// selected={selected}
|
|
104
|
+
contextMenuItems: contextMenuItems, customColumns: customColumns, columns: columns, editableColumns: editableColumns, editable: true, onEditComplete: onEditComplete,
|
|
105
|
+
// leftColumns={leftColumns}
|
|
106
|
+
gridOptions: {
|
|
107
|
+
// defaultFilterValue: filterValue,
|
|
108
|
+
// remoteFilter: false,
|
|
109
|
+
// multiSelect: true,
|
|
110
|
+
// pagination: 'local',
|
|
111
|
+
// defaultLimit: 100,
|
|
112
|
+
// limit: 100,
|
|
113
|
+
// pageSizes: [100],
|
|
114
|
+
// rowIndexColumn: true,
|
|
115
|
+
// checkboxColumn: true,
|
|
116
|
+
}, dataSource: dataSource }));
|
|
117
|
+
}
|
|
118
|
+
export default ExampleGrid;
|
|
@@ -1,84 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function
|
|
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
|
-
exports.func_selection = func_selection;
|
|
1
|
+
function get_parentId(obj) {
|
|
2
|
+
return obj.__parent__table_id || obj.parent;
|
|
3
|
+
}
|
|
4
|
+
function get_selfId(obj) {
|
|
5
|
+
return obj.__table_id;
|
|
6
|
+
}
|
|
7
|
+
//given an array of rows, fixes parent,child relations
|
|
8
|
+
export function fix_parent_child_relations(rows) {
|
|
9
|
+
if (!Array.isArray(rows))
|
|
10
|
+
rows = [];
|
|
11
|
+
const anyparentid = rows.find((r) => get_parentId(r));
|
|
12
|
+
const anyselfid = rows.find((r) => get_selfId(r));
|
|
13
|
+
if (!anyparentid || !anyselfid)
|
|
14
|
+
return rows;
|
|
15
|
+
const converted_rows = rows
|
|
16
|
+
.filter((r) => r != null)
|
|
17
|
+
.map((r) => {
|
|
18
|
+
return { parent: get_parentId(r), self: get_selfId(r), data: r };
|
|
19
|
+
});
|
|
20
|
+
const top_level_rows = converted_rows.filter((r) => !r.parent);
|
|
21
|
+
const any_child = converted_rows.find((r) => Boolean(r.parent));
|
|
22
|
+
if (any_child) {
|
|
23
|
+
//find children of top-level parents:
|
|
24
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
25
|
+
const mrow = top_level_rows[index];
|
|
26
|
+
assign_children(mrow, converted_rows);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return top_level_rows.map((r) => r.data);
|
|
30
|
+
}
|
|
31
|
+
function assign_children(row, all_rows) {
|
|
32
|
+
const my_children = all_rows.filter((s) => row.self == s.parent);
|
|
33
|
+
if (my_children.length > 0) {
|
|
34
|
+
//find children of my children:
|
|
35
|
+
for (let index = 0; index < my_children.length; index++) {
|
|
36
|
+
const child = my_children[index];
|
|
37
|
+
assign_children(child, all_rows);
|
|
38
|
+
}
|
|
39
|
+
row.data.__children = my_children.map((r) => r.data);
|
|
40
|
+
}
|
|
41
|
+
else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0)
|
|
42
|
+
row.data.__children = undefined;
|
|
43
|
+
}
|
|
44
|
+
export class func_selection {
|
|
45
|
+
static getVirtualElement(x = 0, y = 0) {
|
|
46
|
+
return () => ({
|
|
47
|
+
getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static generateGetBoundingClientRect(x = 0, y = 0) {
|
|
51
|
+
return () => ({
|
|
52
|
+
width: 0,
|
|
53
|
+
height: 0,
|
|
54
|
+
top: y,
|
|
55
|
+
right: x,
|
|
56
|
+
bottom: y,
|
|
57
|
+
left: x,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static get_selectedText() {
|
|
61
|
+
var text = '';
|
|
62
|
+
if (window.getSelection) {
|
|
63
|
+
text = window.getSelection()?.toString();
|
|
64
|
+
}
|
|
65
|
+
else if (document.selection &&
|
|
66
|
+
document.selection.type != 'Control') {
|
|
67
|
+
text = document.selection.createRange()?.text;
|
|
68
|
+
}
|
|
69
|
+
return text || '';
|
|
70
|
+
}
|
|
71
|
+
static has_selection() {
|
|
72
|
+
const slct = window.getSelection();
|
|
73
|
+
if (slct == null)
|
|
74
|
+
return false;
|
|
75
|
+
if (slct.type == null)
|
|
76
|
+
return func_selection.get_selectedText().length !== 0;
|
|
77
|
+
if (slct.type === 'Range')
|
|
78
|
+
return true;
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|