@azrico/reactgrid 1.0.20 → 1.0.21
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 +12 -8
- package/dist/src/index.js +10 -16
- package/dist/src/views/DataGrid.d.ts +1 -1
- package/dist/src/views/DataGrid.js +17 -3
- package/package.json +1 -1
- package/src/example.tsx +25 -9
- package/src/index.tsx +9 -9
- package/src/views/DataGrid.tsx +16 -6
package/dist/src/example.js
CHANGED
|
@@ -84,16 +84,16 @@ function ExampleGrid() {
|
|
|
84
84
|
return _react.default.createElement("div", null, _react.default.createElement("div", null, 'Test'));
|
|
85
85
|
};
|
|
86
86
|
const [selected, setSelected] = _react.default.useState(null);
|
|
87
|
-
const [rows, set_rows] = _react.default.useState([]);
|
|
88
87
|
const onSelectionChange = _react.default.useCallback(({
|
|
89
88
|
selected
|
|
90
89
|
}) => {
|
|
91
90
|
setSelected(selected);
|
|
92
91
|
}, []);
|
|
93
|
-
_react.default.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
93
|
+
return {
|
|
94
|
+
data: getData(),
|
|
95
|
+
count: 999
|
|
96
|
+
};
|
|
97
97
|
}, []);
|
|
98
98
|
return _react.default.createElement(_DataGrid.default, {
|
|
99
99
|
dark: true,
|
|
@@ -103,12 +103,16 @@ function ExampleGrid() {
|
|
|
103
103
|
contextMenuItems: contextMenuItems,
|
|
104
104
|
customColumns: customColumns,
|
|
105
105
|
columns: columns,
|
|
106
|
-
rows: rows,
|
|
107
|
-
leftColumns: leftColumns,
|
|
108
106
|
gridOptions: {
|
|
107
|
+
pagination: 'remote',
|
|
108
|
+
defaultLimit: 100,
|
|
109
|
+
limit: 100,
|
|
110
|
+
pageSizes: [100],
|
|
109
111
|
rowIndexColumn: true,
|
|
110
112
|
checkboxColumn: true
|
|
111
|
-
}
|
|
113
|
+
},
|
|
114
|
+
dataSource: dataSource,
|
|
115
|
+
leftColumns: leftColumns
|
|
112
116
|
});
|
|
113
117
|
}
|
|
114
118
|
var _default = ExampleGrid;
|
package/dist/src/index.js
CHANGED
|
@@ -17,21 +17,15 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
|
-
var _example = _interopRequireDefault(require("./example"));
|
|
21
|
-
var _react = _interopRequireDefault(require("react"));
|
|
22
|
-
var _client = _interopRequireDefault(require("react-dom/client"));
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
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); }
|
|
25
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; }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (process.env
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} else
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// set defaults
|
|
37
|
-
}
|
|
22
|
+
var _default = _DataGrid.default; // if (process.env!.NODE_ENV === 'production') {
|
|
23
|
+
// // set production urls
|
|
24
|
+
// // enable sentry
|
|
25
|
+
// } else if (process.env!.NODE_ENV === 'development') {
|
|
26
|
+
// const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
27
|
+
// root.render(<ExampleGrid />);
|
|
28
|
+
// } else {
|
|
29
|
+
// // set defaults
|
|
30
|
+
// }
|
|
31
|
+
exports.default = _default;
|
|
@@ -33,7 +33,7 @@ type customColumnData = {
|
|
|
33
33
|
type GridOptions = Partial<TypeDataGridProps>;
|
|
34
34
|
export type AzGridProps = {
|
|
35
35
|
columns?: columnOrString[];
|
|
36
|
-
|
|
36
|
+
dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
37
37
|
licenseKey?: string;
|
|
38
38
|
gridOptions?: GridOptions;
|
|
39
39
|
columnExtensions?: Array<{
|
|
@@ -43,12 +43,26 @@ function AzGrid(props) {
|
|
|
43
43
|
/* Row changes */
|
|
44
44
|
/* -------------------------------------------------------------------------- */
|
|
45
45
|
const dataSource = _react.default.useCallback(async dt => {
|
|
46
|
-
let result_rows =
|
|
47
|
-
|
|
46
|
+
let result_rows = [];
|
|
47
|
+
let result_data = undefined;
|
|
48
|
+
if (typeof props.dataSource === 'function') {
|
|
49
|
+
result_data = await props.dataSource(dt);
|
|
50
|
+
if (typeof result_data === 'object') {
|
|
51
|
+
result_rows = result_data.data;
|
|
52
|
+
} else result_rows = result_data;
|
|
53
|
+
} else {
|
|
54
|
+
result_rows = props.dataSource || [];
|
|
55
|
+
}
|
|
48
56
|
if (!Array.isArray(result_rows)) result_rows = [result_rows];
|
|
49
57
|
if (props.allowChildRows) result_rows = (0, _helpers.fix_parent_child_relations)(result_rows);
|
|
58
|
+
if (result_data && typeof result_data === 'object') {
|
|
59
|
+
return {
|
|
60
|
+
...result_data,
|
|
61
|
+
data: result_rows
|
|
62
|
+
};
|
|
63
|
+
}
|
|
50
64
|
return result_rows;
|
|
51
|
-
}, [props.
|
|
65
|
+
}, [props.dataSource]);
|
|
52
66
|
return _react.default.createElement(DataGrid, {
|
|
53
67
|
...props,
|
|
54
68
|
columns: cached_columns,
|
package/package.json
CHANGED
package/src/example.tsx
CHANGED
|
@@ -28,10 +28,20 @@ function getData() {
|
|
|
28
28
|
fd.push({ __table_id: String(index), username: 'user-' + index, age: 20 });
|
|
29
29
|
if (index % 5 == 0) {
|
|
30
30
|
const sub_selfid = 's' + index;
|
|
31
|
-
fd.push({
|
|
31
|
+
fd.push({
|
|
32
|
+
__table_id: sub_selfid,
|
|
33
|
+
__parent__table_id: String(index),
|
|
34
|
+
username: 'sub-' + index,
|
|
35
|
+
age: 20,
|
|
36
|
+
});
|
|
32
37
|
if (index % 2 == 0) {
|
|
33
38
|
const sub2_selfid = 'ss' + index;
|
|
34
|
-
fd.push({
|
|
39
|
+
fd.push({
|
|
40
|
+
__table_id: sub2_selfid,
|
|
41
|
+
__parent__table_id: sub_selfid,
|
|
42
|
+
username: 'sub2-' + index,
|
|
43
|
+
age: 20,
|
|
44
|
+
});
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
}
|
|
@@ -47,16 +57,15 @@ export function ExampleGrid() {
|
|
|
47
57
|
);
|
|
48
58
|
};
|
|
49
59
|
const [selected, setSelected] = React.useState(null);
|
|
50
|
-
|
|
60
|
+
|
|
51
61
|
const onSelectionChange = React.useCallback(({ selected }) => {
|
|
52
62
|
setSelected(selected);
|
|
53
63
|
}, []);
|
|
54
64
|
|
|
55
|
-
React.
|
|
56
|
-
|
|
57
|
-
set_rows(getData());
|
|
58
|
-
}, 1000);
|
|
65
|
+
const dataSource = React.useCallback(async (dt) => {
|
|
66
|
+
return { data: getData(), count: 999 };
|
|
59
67
|
}, []);
|
|
68
|
+
|
|
60
69
|
return (
|
|
61
70
|
<AzGrid
|
|
62
71
|
dark
|
|
@@ -66,9 +75,16 @@ export function ExampleGrid() {
|
|
|
66
75
|
contextMenuItems={contextMenuItems}
|
|
67
76
|
customColumns={customColumns}
|
|
68
77
|
columns={columns}
|
|
69
|
-
|
|
78
|
+
gridOptions={{
|
|
79
|
+
pagination: 'remote',
|
|
80
|
+
defaultLimit: 100,
|
|
81
|
+
limit: 100,
|
|
82
|
+
pageSizes: [100],
|
|
83
|
+
rowIndexColumn: true,
|
|
84
|
+
checkboxColumn: true,
|
|
85
|
+
}}
|
|
86
|
+
dataSource={dataSource}
|
|
70
87
|
leftColumns={leftColumns}
|
|
71
|
-
gridOptions={{ rowIndexColumn: true, checkboxColumn: true }}
|
|
72
88
|
/>
|
|
73
89
|
);
|
|
74
90
|
}
|
package/src/index.tsx
CHANGED
|
@@ -7,12 +7,12 @@ import React from 'react';
|
|
|
7
7
|
import ReactDOM from 'react-dom/client';
|
|
8
8
|
export default AzGrid;
|
|
9
9
|
|
|
10
|
-
if (process.env!.NODE_ENV === 'production') {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} else if (process.env!.NODE_ENV === 'development') {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} else {
|
|
17
|
-
|
|
18
|
-
}
|
|
10
|
+
// if (process.env!.NODE_ENV === 'production') {
|
|
11
|
+
// // set production urls
|
|
12
|
+
// // enable sentry
|
|
13
|
+
// } else if (process.env!.NODE_ENV === 'development') {
|
|
14
|
+
// const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
15
|
+
// root.render(<ExampleGrid />);
|
|
16
|
+
// } else {
|
|
17
|
+
// // set defaults
|
|
18
|
+
// }
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -55,7 +55,7 @@ type GridOptions = Partial<TypeDataGridProps>;
|
|
|
55
55
|
/* -------------------------------------------------------------------------- */
|
|
56
56
|
export type AzGridProps = {
|
|
57
57
|
columns?: columnOrString[];
|
|
58
|
-
|
|
58
|
+
dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
59
59
|
|
|
60
60
|
licenseKey?: string;
|
|
61
61
|
|
|
@@ -134,15 +134,25 @@ export function AzGrid(props: AzGridProps) {
|
|
|
134
134
|
/* -------------------------------------------------------------------------- */
|
|
135
135
|
const dataSource = React.useCallback(
|
|
136
136
|
async (dt) => {
|
|
137
|
-
let result_rows =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
let result_rows: any[] = [];
|
|
138
|
+
let result_data: any = undefined;
|
|
139
|
+
if (typeof props.dataSource === 'function') {
|
|
140
|
+
result_data = await props.dataSource(dt);
|
|
141
|
+
if (typeof result_data === 'object') {
|
|
142
|
+
result_rows = result_data.data;
|
|
143
|
+
} else result_rows = result_data;
|
|
144
|
+
} else {
|
|
145
|
+
result_rows = props.dataSource || [];
|
|
146
|
+
}
|
|
141
147
|
if (!Array.isArray(result_rows)) result_rows = [result_rows];
|
|
142
148
|
if (props.allowChildRows) result_rows = fix_parent_child_relations(result_rows);
|
|
149
|
+
|
|
150
|
+
if (result_data && typeof result_data === 'object') {
|
|
151
|
+
return { ...result_data, data: result_rows };
|
|
152
|
+
}
|
|
143
153
|
return result_rows;
|
|
144
154
|
},
|
|
145
|
-
[props.
|
|
155
|
+
[props.dataSource]
|
|
146
156
|
);
|
|
147
157
|
return (
|
|
148
158
|
<DataGrid
|