@azrico/reactgrid 1.1.13 → 1.1.15
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.d.ts +3 -0
- package/dist/index.js +21 -0
- package/dist/src/example.d.ts +4 -0
- package/dist/src/example.js +130 -0
- package/dist/src/func/helpers.d.ts +29 -0
- package/dist/src/func/helpers.js +80 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +30 -0
- package/dist/src/themes/base_styles.css +26 -0
- package/dist/src/themes/grid.css +20 -0
- package/dist/src/views/DataGrid.d.ts +70 -0
- package/dist/src/views/DataGrid.js +429 -0
- package/dist/src/views/index.d.ts +3 -0
- package/dist/src/views/index.js +23 -0
- package/package.json +2 -2
- package/src/example.tsx +8 -0
- package/src/index.tsx +7 -3
- package/src/views/DataGrid.tsx +72 -22
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
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;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ExampleGrid: true
|
|
8
|
+
};
|
|
9
|
+
exports.ExampleGrid = ExampleGrid;
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
var _DataGrid = _interopRequireWildcard(require("./views/DataGrid"));
|
|
12
|
+
Object.keys(_DataGrid).forEach(function (key) {
|
|
13
|
+
if (key === "default" || key === "__esModule") return;
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
+
if (key in exports && exports[key] === _DataGrid[key]) return;
|
|
16
|
+
Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _DataGrid[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
var _react = _interopRequireDefault(require("react"));
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
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
|
+
const columns = [{
|
|
28
|
+
name: 'name',
|
|
29
|
+
title: 'Category',
|
|
30
|
+
defaultFlex: 1
|
|
31
|
+
}, {
|
|
32
|
+
name: 'job',
|
|
33
|
+
title: 'Job',
|
|
34
|
+
type: 'combo',
|
|
35
|
+
items: ['Engineer', 'Doctor'],
|
|
36
|
+
defaultFlex: 1
|
|
37
|
+
}];
|
|
38
|
+
const leftColumns = ['username', 'row'];
|
|
39
|
+
const customColumns = [{
|
|
40
|
+
name: 'job',
|
|
41
|
+
render: () => {
|
|
42
|
+
return _react.default.createElement("div", null, "test");
|
|
43
|
+
}
|
|
44
|
+
}];
|
|
45
|
+
const filterValue = [{
|
|
46
|
+
name: 'name',
|
|
47
|
+
operator: 'contains',
|
|
48
|
+
type: 'string',
|
|
49
|
+
value: ''
|
|
50
|
+
}];
|
|
51
|
+
const contextMenuItems = ['test'];
|
|
52
|
+
function getData() {
|
|
53
|
+
const fd = [];
|
|
54
|
+
for (let index = 0; index < 200; index++) {
|
|
55
|
+
fd.push({
|
|
56
|
+
__table_id: String(index),
|
|
57
|
+
name: 'user-' + index,
|
|
58
|
+
age: 20
|
|
59
|
+
});
|
|
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
|
+
}
|
|
79
|
+
|
|
80
|
+
return fd;
|
|
81
|
+
}
|
|
82
|
+
function ExampleGrid() {
|
|
83
|
+
const [ds_reset, set_ds_reset] = _react.default.useState(0);
|
|
84
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
85
|
+
//console.log('Start loading');
|
|
86
|
+
return await new Promise(resolve => {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
//console.log('end loading');
|
|
89
|
+
resolve(getData());
|
|
90
|
+
}, 1000);
|
|
91
|
+
});
|
|
92
|
+
}, [ds_reset]);
|
|
93
|
+
const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
|
|
94
|
+
console.log((rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
|
|
95
|
+
}, []);
|
|
96
|
+
const onRowClick = _react.default.useCallback((index, rowdata) => {
|
|
97
|
+
//console.log(rowdata?.data || rowdata);
|
|
98
|
+
}, []);
|
|
99
|
+
function rst_ds() {
|
|
100
|
+
//console.log('rst_ds');
|
|
101
|
+
set_ds_reset(s => s + 1);
|
|
102
|
+
}
|
|
103
|
+
return _react.default.createElement(_DataGrid.default, {
|
|
104
|
+
dark: true,
|
|
105
|
+
onRowClick: onRowClick,
|
|
106
|
+
onRowDoubleClick: onRowDoubleClick,
|
|
107
|
+
// allowChildRows
|
|
108
|
+
// onSelectionChange={onSelectionChange}
|
|
109
|
+
// selected={selected}
|
|
110
|
+
contextMenuItems: contextMenuItems,
|
|
111
|
+
// customColumns={customColumns}
|
|
112
|
+
columns: columns,
|
|
113
|
+
editable: true,
|
|
114
|
+
// leftColumns={leftColumns}
|
|
115
|
+
gridOptions: {
|
|
116
|
+
// defaultFilterValue: filterValue,
|
|
117
|
+
// remoteFilter: false,
|
|
118
|
+
// multiSelect: true,
|
|
119
|
+
// pagination: 'local',
|
|
120
|
+
// defaultLimit: 100,
|
|
121
|
+
// limit: 100,
|
|
122
|
+
// pageSizes: [100],
|
|
123
|
+
// rowIndexColumn: true,
|
|
124
|
+
// checkboxColumn: true,
|
|
125
|
+
},
|
|
126
|
+
dataSource: dataSource
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
var _default = ExampleGrid;
|
|
130
|
+
exports.default = _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type mrow = {
|
|
2
|
+
__parent__table_id: any;
|
|
3
|
+
__table_id: any;
|
|
4
|
+
__children?: any[];
|
|
5
|
+
};
|
|
6
|
+
export declare function fix_parent_child_relations<T extends mrow>(rows: T[]): T[];
|
|
7
|
+
export declare class func_selection {
|
|
8
|
+
static getVirtualElement(x?: number, y?: number): () => {
|
|
9
|
+
getBoundingClientRect: () => {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
static generateGetBoundingClientRect(x?: number, y?: number): () => {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
top: number;
|
|
22
|
+
right: number;
|
|
23
|
+
bottom: number;
|
|
24
|
+
left: number;
|
|
25
|
+
};
|
|
26
|
+
static get_selectedText(): string;
|
|
27
|
+
static has_selection(): boolean;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fix_parent_child_relations = fix_parent_child_relations;
|
|
7
|
+
exports.func_selection = void 0;
|
|
8
|
+
function get_parentId(obj) {
|
|
9
|
+
return obj.__parent__table_id || obj.parent;
|
|
10
|
+
}
|
|
11
|
+
function get_selfId(obj) {
|
|
12
|
+
return obj.__table_id;
|
|
13
|
+
}
|
|
14
|
+
//given an array of rows, fixes parent,child relations
|
|
15
|
+
function fix_parent_child_relations(rows) {
|
|
16
|
+
if (!Array.isArray(rows)) rows = [];
|
|
17
|
+
const converted_rows = rows.filter(r => r != null).map(r => {
|
|
18
|
+
return {
|
|
19
|
+
parent: get_parentId(r),
|
|
20
|
+
self: get_selfId(r),
|
|
21
|
+
data: r
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
const top_level_rows = converted_rows.filter(r => !r.parent);
|
|
25
|
+
//find children of top-level parents:
|
|
26
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
27
|
+
const mrow = top_level_rows[index];
|
|
28
|
+
assign_children(mrow, converted_rows);
|
|
29
|
+
}
|
|
30
|
+
const result = top_level_rows.map(r => r.data);
|
|
31
|
+
//console.log(result);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
function assign_children(row, all_rows) {
|
|
35
|
+
const my_children = all_rows.filter(s => row.self == s.parent);
|
|
36
|
+
if (my_children.length > 0) {
|
|
37
|
+
//find children of my children:
|
|
38
|
+
for (let index = 0; index < my_children.length; index++) {
|
|
39
|
+
const child = my_children[index];
|
|
40
|
+
assign_children(child, all_rows);
|
|
41
|
+
}
|
|
42
|
+
row.data.__children = my_children.map(r => r.data);
|
|
43
|
+
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
|
|
44
|
+
}
|
|
45
|
+
class func_selection {
|
|
46
|
+
static getVirtualElement(x = 0, y = 0) {
|
|
47
|
+
return () => ({
|
|
48
|
+
getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static generateGetBoundingClientRect(x = 0, y = 0) {
|
|
52
|
+
return () => ({
|
|
53
|
+
width: 0,
|
|
54
|
+
height: 0,
|
|
55
|
+
top: y,
|
|
56
|
+
right: x,
|
|
57
|
+
bottom: y,
|
|
58
|
+
left: x
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
static get_selectedText() {
|
|
62
|
+
var text = '';
|
|
63
|
+
if (window.getSelection) {
|
|
64
|
+
var _window$getSelection;
|
|
65
|
+
text = (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString();
|
|
66
|
+
} else if (document.selection && document.selection.type != 'Control') {
|
|
67
|
+
var _document$selection$c;
|
|
68
|
+
text = (_document$selection$c = document.selection.createRange()) === null || _document$selection$c === void 0 ? void 0 : _document$selection$c.text;
|
|
69
|
+
}
|
|
70
|
+
return text || '';
|
|
71
|
+
}
|
|
72
|
+
static has_selection() {
|
|
73
|
+
const slct = window.getSelection();
|
|
74
|
+
if (slct == null) return false;
|
|
75
|
+
if (slct.type == null) return func_selection.get_selectedText().length !== 0;
|
|
76
|
+
if (slct.type === 'Range') return true;
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.func_selection = func_selection;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _DataGrid = _interopRequireWildcard(require("./views/DataGrid"));
|
|
9
|
+
Object.keys(_DataGrid).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] === _DataGrid[key]) return;
|
|
13
|
+
Object.defineProperty(exports, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _DataGrid[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
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
|
+
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
|
+
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
|
+
var _default = _DataGrid.default;
|
|
28
|
+
exports.default = _default;
|
|
29
|
+
const root = _client.default.createRoot(document.getElementById('testroot'));
|
|
30
|
+
root.render(_react.default.createElement(_example.default, null));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.azgrid-container {
|
|
2
|
+
height: 100%;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
.azgrid-borderbox {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
.azgrid-filler {
|
|
9
|
+
height: 100%;
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
.azgrid-nooverflow {
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
.azgrid-testborder {
|
|
16
|
+
border: 3px solid red;
|
|
17
|
+
}
|
|
18
|
+
.azgrid-pad50px {
|
|
19
|
+
padding: 50px;
|
|
20
|
+
}
|
|
21
|
+
.azgrid-nopad {
|
|
22
|
+
padding: 0;
|
|
23
|
+
}
|
|
24
|
+
.azgrid-nomargin {
|
|
25
|
+
margin: 0;
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* .InovuaReactDataGrid {
|
|
2
|
+
--grid-bg: '#fff';
|
|
3
|
+
}
|
|
4
|
+
.InovuaReactDataGrid {
|
|
5
|
+
background: var(--grid-bg) !important;
|
|
6
|
+
}
|
|
7
|
+
.InovuaReactDataGrid__header {
|
|
8
|
+
background: var(--grid-bg) !important;
|
|
9
|
+
}
|
|
10
|
+
.InovuaReactDataGrid__row {
|
|
11
|
+
background: var(--grid-bg) !important;
|
|
12
|
+
}
|
|
13
|
+
.InovuaReactDataGrid__cell {
|
|
14
|
+
background: var(--grid-bg) !important;
|
|
15
|
+
} */
|
|
16
|
+
.InovuaReactDataGrid__cell .InovuaReactDataGrid__cell__content {
|
|
17
|
+
height: 100%;
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import '@inovua/reactdatagrid-enterprise/index.css';
|
|
2
|
+
import '@inovua/reactdatagrid-enterprise/theme/default-dark.css';
|
|
3
|
+
import '@inovua/reactdatagrid-enterprise/theme/amber-dark.css';
|
|
4
|
+
import '../themes/base_styles.css';
|
|
5
|
+
import '../themes/grid.css';
|
|
6
|
+
import { ConvertableToMenuItem } from '@azrico/controls';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
|
|
9
|
+
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
10
|
+
export type ColumnDefinition = TypeColumn;
|
|
11
|
+
export type CellDefinition = any;
|
|
12
|
+
export type RowDefinition = any;
|
|
13
|
+
export type RowProps = TypeRowProps;
|
|
14
|
+
export type RowSelectionValue = TypeRowSelection;
|
|
15
|
+
export type DataRowDefinition = any;
|
|
16
|
+
export type FilterTypes = TypeFilterTypes;
|
|
17
|
+
export type DataSourceDefinition = TypeDataSource;
|
|
18
|
+
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
19
|
+
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
20
|
+
type loose_column_names = {
|
|
21
|
+
key: string;
|
|
22
|
+
field: string;
|
|
23
|
+
columnName: string;
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
type loose_column_fields = loose_column_names & {
|
|
27
|
+
title: string;
|
|
28
|
+
type: string;
|
|
29
|
+
items: any[];
|
|
30
|
+
};
|
|
31
|
+
export type LooseColumnDefinition = Partial<loose_column_fields & ColumnDefinition>;
|
|
32
|
+
type columnOrString = string | LooseColumnDefinition;
|
|
33
|
+
type customColumnData = {
|
|
34
|
+
name: string;
|
|
35
|
+
render: (cell: any, formatterParams: any, onRendered: any) => React.ReactNode | undefined | null;
|
|
36
|
+
};
|
|
37
|
+
type GridOptions = Partial<TypeDataGridProps>;
|
|
38
|
+
export type AzGridProps = {
|
|
39
|
+
columns?: columnOrString[];
|
|
40
|
+
dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
41
|
+
licenseKey?: string;
|
|
42
|
+
gridOptions?: GridOptions;
|
|
43
|
+
columnExtensions?: Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
} & Partial<ColumnDefinition>>;
|
|
46
|
+
editableColumns?: string[];
|
|
47
|
+
leftColumns?: string[];
|
|
48
|
+
rightColumns?: string[];
|
|
49
|
+
customColumns?: customColumnData[];
|
|
50
|
+
contextMenuItems?: ConvertableToMenuItem[];
|
|
51
|
+
highlightedRow?: any;
|
|
52
|
+
RowDetail?: RowDetailsFunc;
|
|
53
|
+
selected?: RowSelectionValue;
|
|
54
|
+
onEditComplete?: (editInfo: TypeEditInfo) => void;
|
|
55
|
+
onSelectionChange?: OnSelectionChangeFunc;
|
|
56
|
+
onRowClick?: (rowIndex: number, row: any) => void;
|
|
57
|
+
onRowDoubleClick?: (rowIndex: number, row: any) => void;
|
|
58
|
+
onLimitChange?: (v: number) => void;
|
|
59
|
+
onSkipChange?: (v: number) => void;
|
|
60
|
+
skip?: number;
|
|
61
|
+
limit?: number;
|
|
62
|
+
loading?: boolean;
|
|
63
|
+
dark?: boolean;
|
|
64
|
+
editable: boolean;
|
|
65
|
+
allowChildRows?: boolean;
|
|
66
|
+
looseCacheCheck?: boolean;
|
|
67
|
+
className?: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function AzGrid(props: AzGridProps): JSX.Element;
|
|
70
|
+
export default AzGrid;
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AzGrid = AzGrid;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
require("@inovua/reactdatagrid-enterprise/index.css");
|
|
9
|
+
require("@inovua/reactdatagrid-enterprise/theme/default-dark.css");
|
|
10
|
+
require("@inovua/reactdatagrid-enterprise/theme/amber-dark.css");
|
|
11
|
+
require("../themes/base_styles.css");
|
|
12
|
+
require("../themes/grid.css");
|
|
13
|
+
var _controls = require("@azrico/controls");
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
var _helpers = require("../func/helpers");
|
|
16
|
+
var _reactdatagridEnterprise = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise"));
|
|
17
|
+
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
18
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
19
|
+
var _object = require("@azrico/object");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
/* -------------------------------------------------------------------------- */
|
|
22
|
+
// const defaultfilterTypes: FilterTypes = {
|
|
23
|
+
// string: {
|
|
24
|
+
// type: 'string',
|
|
25
|
+
// emptyValue: '',
|
|
26
|
+
// operators: [
|
|
27
|
+
// {
|
|
28
|
+
// name: 'contains',
|
|
29
|
+
// fn: ({ value, filterValue, data }) => {
|
|
30
|
+
// console.log('fn');
|
|
31
|
+
// return !filterValue ? true : value.indexOf(filterValue) != -1;
|
|
32
|
+
// },
|
|
33
|
+
// },
|
|
34
|
+
// ],
|
|
35
|
+
// },
|
|
36
|
+
// };
|
|
37
|
+
const defaultOptions = {
|
|
38
|
+
//filterTypes: defaultfilterTypes,
|
|
39
|
+
remoteFilter: false,
|
|
40
|
+
remoteSort: false,
|
|
41
|
+
editStartEvent: 'click',
|
|
42
|
+
rowReorderColumn: false,
|
|
43
|
+
resizable: true,
|
|
44
|
+
rowIndexColumn: true
|
|
45
|
+
};
|
|
46
|
+
const forcedOptions = {
|
|
47
|
+
idProperty: '__table_id',
|
|
48
|
+
nodesProperty: '__children'
|
|
49
|
+
};
|
|
50
|
+
const defaultColumnOptions = {
|
|
51
|
+
draggable: false,
|
|
52
|
+
lockable: false
|
|
53
|
+
};
|
|
54
|
+
const dynamic_option_names = ['selected', 'loading', 'limit', 'skip'];
|
|
55
|
+
/* -------------------------------------------------------------------------- */
|
|
56
|
+
function AzGrid(props) {
|
|
57
|
+
/* -------------------------------------------------------------------------- */
|
|
58
|
+
/* Columns */
|
|
59
|
+
/* -------------------------------------------------------------------------- */
|
|
60
|
+
const cached_columns = _react.default.useMemo(() => {
|
|
61
|
+
return ApplyColumnData(props);
|
|
62
|
+
}, [props.columns, props.leftColumns, props.rightColumns, props.editableColumns, props.columnExtensions, props.customColumns]);
|
|
63
|
+
/* -------------------------------------------------------------------------- */
|
|
64
|
+
/* Row changes */
|
|
65
|
+
/* -------------------------------------------------------------------------- */
|
|
66
|
+
const cached_data = _react.default.useRef();
|
|
67
|
+
const last_cache_info = _react.default.useRef();
|
|
68
|
+
const dataSource = _react.default.useCallback(async dt => {
|
|
69
|
+
let result_data = undefined;
|
|
70
|
+
let isUsingCache = false;
|
|
71
|
+
const cacheInfo = {
|
|
72
|
+
ds: props.dataSource,
|
|
73
|
+
skip: dt.skip,
|
|
74
|
+
limit: dt.limit
|
|
75
|
+
};
|
|
76
|
+
//check if we can used cached data
|
|
77
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
78
|
+
if (!validateCache(last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
79
|
+
cached_data.current = undefined;
|
|
80
|
+
last_cache_info.current = cacheInfo;
|
|
81
|
+
}
|
|
82
|
+
if (cached_data.current) {
|
|
83
|
+
//cache is valid, use the cache
|
|
84
|
+
isUsingCache = true;
|
|
85
|
+
result_data = cached_data.current;
|
|
86
|
+
} else {
|
|
87
|
+
//cache is invalid, use the datasource again
|
|
88
|
+
isUsingCache = false;
|
|
89
|
+
if (typeof props.dataSource === 'function') {
|
|
90
|
+
result_data = await props.dataSource(dt);
|
|
91
|
+
} else result_data = props.dataSource;
|
|
92
|
+
}
|
|
93
|
+
//making sure the datasource is a valid object :
|
|
94
|
+
if (!result_data) result_data = [];
|
|
95
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
96
|
+
data: result_data
|
|
97
|
+
};
|
|
98
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
99
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
100
|
+
if (!isUsingCache && props.allowChildRows) result_data.data = (0, _helpers.fix_parent_child_relations)(result_data.data);
|
|
101
|
+
if (!result_data.count) result_data.count = result_data.data.length;
|
|
102
|
+
//update cache
|
|
103
|
+
cached_data.current = result_data;
|
|
104
|
+
return result_data;
|
|
105
|
+
}, [props.dataSource]);
|
|
106
|
+
return _react.default.createElement(DataGrid, {
|
|
107
|
+
...props,
|
|
108
|
+
columns: cached_columns,
|
|
109
|
+
dataSource: dataSource,
|
|
110
|
+
highlightedRow: props.highlightedRow
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/* -------------------------------------------------------------------------- */
|
|
114
|
+
function DataGrid(props) {
|
|
115
|
+
const {
|
|
116
|
+
columns,
|
|
117
|
+
dataSource,
|
|
118
|
+
dark,
|
|
119
|
+
contextMenuItems
|
|
120
|
+
} = props;
|
|
121
|
+
/* -------------------------------------------------------------------------- */
|
|
122
|
+
const gridRef = _react.default.useRef(null);
|
|
123
|
+
const click_data = _react.default.useRef(null);
|
|
124
|
+
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
125
|
+
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
126
|
+
_react.default.useEffect(() => {
|
|
127
|
+
click_data.current = {};
|
|
128
|
+
}, [dataSource]);
|
|
129
|
+
/* --------------------------------- events --------------------------------- */
|
|
130
|
+
const onRowContextMenu = _react.default.useCallback((rowProps, event) => {
|
|
131
|
+
if (_helpers.func_selection.has_selection()) return;
|
|
132
|
+
update_menuRow(rowProps.data);
|
|
133
|
+
update_menuAnchorEl(_helpers.func_selection.getVirtualElement(event.clientX, event.clientY));
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
}, []);
|
|
136
|
+
const onRowClick = _react.default.useCallback((rowProps, event) => {
|
|
137
|
+
const nowDate = Date.now();
|
|
138
|
+
const lastclick = click_data.current[get_row_id(rowProps)];
|
|
139
|
+
if (lastclick) {
|
|
140
|
+
const diffTime = Math.abs(nowDate - lastclick);
|
|
141
|
+
if (diffTime < 400) {
|
|
142
|
+
props.onRowDoubleClick && props.onRowDoubleClick(rowProps.rowIndex, rowProps.data);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
click_data.current[get_row_id(rowProps)] = nowDate;
|
|
146
|
+
props.onRowClick && props.onRowClick(rowProps.rowIndex, rowProps.data);
|
|
147
|
+
}, []);
|
|
148
|
+
/* ------------------------------- ContextMenu ------------------------------ */
|
|
149
|
+
const update_menuAnchorEl = _react.default.useCallback(el => {
|
|
150
|
+
if (el) {
|
|
151
|
+
set_menuAnchorEl(el);
|
|
152
|
+
} else set_menuAnchorEl(null);
|
|
153
|
+
}, []);
|
|
154
|
+
const update_menuRow = _react.default.useCallback(r => {
|
|
155
|
+
if (r) {
|
|
156
|
+
set_menuRow(r);
|
|
157
|
+
} else set_menuRow(null);
|
|
158
|
+
}, []);
|
|
159
|
+
/* -------------------------------------------------------------------------- */
|
|
160
|
+
/* Create the grid */
|
|
161
|
+
/* -------------------------------------------------------------------------- */
|
|
162
|
+
const base_gridOptions = _react.default.useMemo(() => {
|
|
163
|
+
const firstcolumn = columns[0];
|
|
164
|
+
const licenseKey = props.licenseKey || get_default_key();
|
|
165
|
+
const events = {
|
|
166
|
+
onRowClick: onRowClick,
|
|
167
|
+
onRowContextMenu: onRowContextMenu,
|
|
168
|
+
onSkipChange: props.onSkipChange,
|
|
169
|
+
onLimitChange: props.onLimitChange,
|
|
170
|
+
onEditComplete: props.onEditComplete
|
|
171
|
+
};
|
|
172
|
+
const extra_ops = {
|
|
173
|
+
onSelectionChange: props.onSelectionChange,
|
|
174
|
+
licenseKey: licenseKey,
|
|
175
|
+
editable: props.editable,
|
|
176
|
+
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
177
|
+
renderRowDetails: props.RowDetail,
|
|
178
|
+
theme: dark ? 'amber-dark' : 'default-light'
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
...defaultOptions,
|
|
182
|
+
...events,
|
|
183
|
+
...extra_ops
|
|
184
|
+
};
|
|
185
|
+
}, [columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
|
|
186
|
+
const static_gridOptions = _react.default.useMemo(() => {
|
|
187
|
+
return {
|
|
188
|
+
...base_gridOptions,
|
|
189
|
+
...props.gridOptions,
|
|
190
|
+
...forcedOptions
|
|
191
|
+
};
|
|
192
|
+
}, [props.gridOptions, base_gridOptions, forcedOptions]);
|
|
193
|
+
const dynamic_gridOptions = _react.default.useMemo(() => {
|
|
194
|
+
const res = {};
|
|
195
|
+
dynamic_option_names.map(r => {
|
|
196
|
+
res[r] = props[r];
|
|
197
|
+
});
|
|
198
|
+
return res;
|
|
199
|
+
}, dynamic_option_names.map(r => props[r]));
|
|
200
|
+
// const { width, height, ref: resize_ref } = useResizeDetector();
|
|
201
|
+
return _react.default.createElement("div", {
|
|
202
|
+
className: (0, _clsx.default)(props.className, 'azgrid-nooverflow', 'azgrid-filler')
|
|
203
|
+
}, _react.default.createElement(_reactdatagridEnterprise.default, {
|
|
204
|
+
...static_gridOptions,
|
|
205
|
+
...dynamic_gridOptions,
|
|
206
|
+
handle: ref => gridRef.current = ref ? ref.current : null,
|
|
207
|
+
className: 'azgrid-filler',
|
|
208
|
+
columns: columns,
|
|
209
|
+
dataSource: dataSource
|
|
210
|
+
}), _react.default.createElement(_controls.ContextMenu, {
|
|
211
|
+
menuAnchorEl: menuAnchorEl,
|
|
212
|
+
set_menuAnchorEl: update_menuAnchorEl,
|
|
213
|
+
menuRow: menuRow,
|
|
214
|
+
items: contextMenuItems
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
/* -------------------------------------------------------------------------- */
|
|
218
|
+
/* -------------------------------------------------------------------------- */
|
|
219
|
+
/* -------------------------------------------------------------------------- */
|
|
220
|
+
/* -------------------------------------------------------------------------- */
|
|
221
|
+
/**
|
|
222
|
+
* merges together all different props for columns
|
|
223
|
+
* to build a single final column data array
|
|
224
|
+
* @param props
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
function ApplyColumnData(props) {
|
|
228
|
+
const final_columns = [];
|
|
229
|
+
let mcols = props.columns || [];
|
|
230
|
+
let mcolExts = props.columnExtensions || [];
|
|
231
|
+
let rightColumns = props.rightColumns || [];
|
|
232
|
+
let leftColumns = props.leftColumns || [];
|
|
233
|
+
let editableColumns = props.editableColumns || [];
|
|
234
|
+
let customColumns = props.customColumns || [];
|
|
235
|
+
if (!Array.isArray(mcols)) return [];
|
|
236
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
237
|
+
mcols.map(r => {
|
|
238
|
+
if (r == null) return null;
|
|
239
|
+
if (typeof r === 'string') return {
|
|
240
|
+
field: r,
|
|
241
|
+
header: r
|
|
242
|
+
};
|
|
243
|
+
if (typeof r === 'object') {
|
|
244
|
+
let final_cl = {
|
|
245
|
+
name: get_col_name(r),
|
|
246
|
+
header: get_col_header(r),
|
|
247
|
+
width: r.width || undefined
|
|
248
|
+
};
|
|
249
|
+
final_cl = {
|
|
250
|
+
...defaultColumnOptions,
|
|
251
|
+
...r,
|
|
252
|
+
...final_cl
|
|
253
|
+
};
|
|
254
|
+
return final_cl;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}).forEach(r => {
|
|
258
|
+
if (r != null) final_columns.push(r);
|
|
259
|
+
});
|
|
260
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
261
|
+
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
262
|
+
const ext = mcolExts[index];
|
|
263
|
+
const ext_cl = get_col_name(ext);
|
|
264
|
+
const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
|
|
265
|
+
if (mcol) {
|
|
266
|
+
for (const key in ext) {
|
|
267
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
271
|
+
}
|
|
272
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
273
|
+
if (Array.isArray(leftColumns)) {
|
|
274
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
275
|
+
const r = get_col_name(leftColumns[index]);
|
|
276
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
277
|
+
if (mcol) {
|
|
278
|
+
mcol.locked = 'start';
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (Array.isArray(rightColumns)) {
|
|
283
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
284
|
+
const r = get_col_name(rightColumns[index]);
|
|
285
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
286
|
+
if (mcol) {
|
|
287
|
+
mcol.locked = 'end';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
292
|
+
if (Array.isArray(editableColumns)) {
|
|
293
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
294
|
+
const r = get_col_name(editableColumns[index]);
|
|
295
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
296
|
+
if (mcol) {
|
|
297
|
+
// mcol.editor = editorWrapper;
|
|
298
|
+
// mcol.editorOptions = {
|
|
299
|
+
// editOnClick: true,
|
|
300
|
+
// };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
305
|
+
const col = final_columns[index];
|
|
306
|
+
if (col.type) {
|
|
307
|
+
switch (col.type) {
|
|
308
|
+
case 'combo':
|
|
309
|
+
case 'select':
|
|
310
|
+
//@ts-ignore
|
|
311
|
+
col.editor = _SelectEditor.default;
|
|
312
|
+
break;
|
|
313
|
+
//case 'number':
|
|
314
|
+
//case 'numberic':
|
|
315
|
+
// col.editor = NumericEditor;
|
|
316
|
+
// break;
|
|
317
|
+
//case 'truefalse':
|
|
318
|
+
//case 'bool':
|
|
319
|
+
// col.editor = BoolEditor;
|
|
320
|
+
// break;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
delete col.type;
|
|
324
|
+
}
|
|
325
|
+
//@ts-ignore
|
|
326
|
+
if (!col.editorProps) col.editorProps = {};
|
|
327
|
+
if (col.items) {
|
|
328
|
+
//@ts-ignore
|
|
329
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
330
|
+
//@ts-ignore
|
|
331
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
332
|
+
//@ts-ignore
|
|
333
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
334
|
+
delete col.items;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/* -------------------------------------------------------------------------- */
|
|
338
|
+
if (Array.isArray(customColumns)) {
|
|
339
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
340
|
+
const r = customColumns[index];
|
|
341
|
+
const rn = get_col_name(r);
|
|
342
|
+
const mcol = final_columns.find(s => get_col_name(s) === rn);
|
|
343
|
+
if (mcol) {
|
|
344
|
+
//@ts-ignore
|
|
345
|
+
mcol.render = r.render;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
350
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
351
|
+
const col = final_columns[index];
|
|
352
|
+
if (!col.name) {
|
|
353
|
+
col.name = get_col_name(col);
|
|
354
|
+
delete col.field;
|
|
355
|
+
delete col.key;
|
|
356
|
+
delete col.columnName;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/* -------------------------------------------------------------------------- */
|
|
360
|
+
console.log(final_columns);
|
|
361
|
+
return final_columns;
|
|
362
|
+
}
|
|
363
|
+
function to_datasource(arr, idProperty) {
|
|
364
|
+
const res = [];
|
|
365
|
+
let index = 0;
|
|
366
|
+
if (Array.isArray(arr)) {
|
|
367
|
+
arr.map(s => {
|
|
368
|
+
let elem = {};
|
|
369
|
+
elem[idProperty] = '_cid_' + index;
|
|
370
|
+
if (typeof s === 'object') elem = {
|
|
371
|
+
...elem,
|
|
372
|
+
...s
|
|
373
|
+
};else elem['label'] = s;
|
|
374
|
+
res.push(elem);
|
|
375
|
+
index++;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return res;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Gets name of a column from its column object
|
|
382
|
+
* @param obj
|
|
383
|
+
* @returns
|
|
384
|
+
*/
|
|
385
|
+
function get_col_name(obj) {
|
|
386
|
+
if (!obj) return 'default';
|
|
387
|
+
if (typeof obj == 'string') return obj;
|
|
388
|
+
if (typeof obj != 'object') return 'default';
|
|
389
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Gets header of a column
|
|
393
|
+
* @param obj
|
|
394
|
+
* @returns
|
|
395
|
+
*/
|
|
396
|
+
function get_col_header(obj) {
|
|
397
|
+
if (!obj) return 'default';
|
|
398
|
+
if (typeof obj == 'string') return obj;
|
|
399
|
+
if (typeof obj != 'object') return 'default';
|
|
400
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Gets name of a column from its column object
|
|
404
|
+
* @param obj
|
|
405
|
+
* @returns
|
|
406
|
+
*/
|
|
407
|
+
function get_row_id(obj) {
|
|
408
|
+
if (!obj) return 'default';
|
|
409
|
+
if (typeof obj == 'string') return obj;
|
|
410
|
+
if (typeof obj != 'object') return 'default';
|
|
411
|
+
return obj.__table_id || obj.id || 'default';
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Gets default activation key for grid plugin
|
|
415
|
+
* @returns
|
|
416
|
+
*/
|
|
417
|
+
function get_default_key() {
|
|
418
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
419
|
+
}
|
|
420
|
+
//check if two cache objects are the same
|
|
421
|
+
function validateCache(current, old, looseCheck = false) {
|
|
422
|
+
if (!old || !(0, _object.object_equals)(current, old)) return false;
|
|
423
|
+
if (looseCheck) return true;
|
|
424
|
+
if (current.ds != old.ds) return false;
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
/* -------------------------------------------------------------------------- */
|
|
428
|
+
var _default = AzGrid;
|
|
429
|
+
exports.default = _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _DataGrid = _interopRequireWildcard(require("./DataGrid"));
|
|
9
|
+
Object.keys(_DataGrid).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] === _DataGrid[key]) return;
|
|
13
|
+
Object.defineProperty(exports, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _DataGrid[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
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
|
+
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
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azrico/reactgrid",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"description": "React Datagrid",
|
|
6
6
|
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@azrico/object": "^1.3.1",
|
|
34
34
|
"@emotion/react": "^11.9.3",
|
|
35
35
|
"@emotion/styled": "^11.9.3",
|
|
36
|
-
"@inovua/reactdatagrid-enterprise": "^5.8.
|
|
36
|
+
"@inovua/reactdatagrid-enterprise": "^5.8.1",
|
|
37
37
|
"clsx": "^1.2.1",
|
|
38
38
|
"react": "^18.2.0",
|
|
39
39
|
"react-resize-detector": "^7.1.2"
|
package/src/example.tsx
CHANGED
|
@@ -11,6 +11,13 @@ const columns = [
|
|
|
11
11
|
title: 'Category',
|
|
12
12
|
defaultFlex: 1,
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
name: 'job',
|
|
16
|
+
title: 'Job',
|
|
17
|
+
type: 'combo',
|
|
18
|
+
items: ['Engineer', 'Doctor'],
|
|
19
|
+
defaultFlex: 1,
|
|
20
|
+
},
|
|
14
21
|
];
|
|
15
22
|
const leftColumns = ['username', 'row'];
|
|
16
23
|
const customColumns = [
|
|
@@ -96,6 +103,7 @@ export function ExampleGrid() {
|
|
|
96
103
|
contextMenuItems={contextMenuItems}
|
|
97
104
|
// customColumns={customColumns}
|
|
98
105
|
columns={columns}
|
|
106
|
+
editable={true}
|
|
99
107
|
// leftColumns={leftColumns}
|
|
100
108
|
gridOptions={
|
|
101
109
|
{
|
package/src/index.tsx
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export * from './views/DataGrid';
|
|
2
2
|
|
|
3
3
|
import AzGrid from './views/DataGrid';
|
|
4
|
-
/* -------------------------------------------------------------------------- */
|
|
5
4
|
import ExampleGrid from './example';
|
|
6
5
|
import React from 'react';
|
|
7
6
|
import ReactDOM from 'react-dom/client';
|
|
7
|
+
|
|
8
|
+
/* -------------------------------------------------------------------------- */
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
8
12
|
export default AzGrid;
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
|
|
15
|
+
root.render(<ExampleGrid />);
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
TypeColumn,
|
|
11
11
|
TypeDataGridProps,
|
|
12
12
|
TypeDataSource,
|
|
13
|
+
TypeEditInfo,
|
|
13
14
|
TypeFilterTypes,
|
|
14
15
|
TypeRowDetailsInfo,
|
|
15
16
|
TypeRowProps,
|
|
@@ -17,7 +18,10 @@ import {
|
|
|
17
18
|
} from '@inovua/reactdatagrid-community/types';
|
|
18
19
|
import { fix_parent_child_relations, func_selection } from '../func/helpers';
|
|
19
20
|
|
|
21
|
+
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';
|
|
22
|
+
import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
|
|
20
23
|
import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
|
|
24
|
+
import SelectEditor from '@inovua/reactdatagrid-community/SelectEditor';
|
|
21
25
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
22
26
|
import clsx from 'clsx';
|
|
23
27
|
import { object_equals } from '@azrico/object';
|
|
@@ -81,6 +85,7 @@ export type AzGridProps = {
|
|
|
81
85
|
|
|
82
86
|
selected?: RowSelectionValue;
|
|
83
87
|
/* -------------------------------------------------------------------------- */
|
|
88
|
+
onEditComplete?: (editInfo: TypeEditInfo) => void;
|
|
84
89
|
onSelectionChange?: OnSelectionChangeFunc;
|
|
85
90
|
|
|
86
91
|
onRowClick?: (rowIndex: number, row: any) => void;
|
|
@@ -93,6 +98,7 @@ export type AzGridProps = {
|
|
|
93
98
|
//
|
|
94
99
|
loading?: boolean;
|
|
95
100
|
dark?: boolean;
|
|
101
|
+
editable: boolean;
|
|
96
102
|
allowChildRows?: boolean;
|
|
97
103
|
looseCacheCheck?: boolean;
|
|
98
104
|
className?: string;
|
|
@@ -125,7 +131,7 @@ const defaultOptions: GridOptions = {
|
|
|
125
131
|
//filterTypes: defaultfilterTypes,
|
|
126
132
|
remoteFilter: false,
|
|
127
133
|
remoteSort: false,
|
|
128
|
-
|
|
134
|
+
editStartEvent: 'click',
|
|
129
135
|
rowReorderColumn: false,
|
|
130
136
|
resizable: true,
|
|
131
137
|
rowIndexColumn: true,
|
|
@@ -277,19 +283,27 @@ function DataGrid(props: DataGridProps) {
|
|
|
277
283
|
const licenseKey = props.licenseKey || get_default_key();
|
|
278
284
|
const events: GridOptions = {
|
|
279
285
|
onRowClick: onRowClick,
|
|
286
|
+
onRowContextMenu: onRowContextMenu,
|
|
280
287
|
onSkipChange: props.onSkipChange,
|
|
281
288
|
onLimitChange: props.onLimitChange,
|
|
282
|
-
|
|
289
|
+
onEditComplete: props.onEditComplete,
|
|
283
290
|
};
|
|
284
291
|
const extra_ops: GridOptions = {
|
|
285
292
|
onSelectionChange: props.onSelectionChange,
|
|
286
293
|
licenseKey: licenseKey,
|
|
294
|
+
editable: props.editable,
|
|
287
295
|
treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
|
|
288
296
|
renderRowDetails: props.RowDetail,
|
|
289
297
|
theme: dark ? 'amber-dark' : 'default-light',
|
|
290
298
|
};
|
|
291
299
|
return { ...defaultOptions, ...events, ...extra_ops };
|
|
292
|
-
}, [
|
|
300
|
+
}, [
|
|
301
|
+
columns,
|
|
302
|
+
props.allowChildRows,
|
|
303
|
+
props.editable,
|
|
304
|
+
props.RowDetail,
|
|
305
|
+
props.onEditComplete,
|
|
306
|
+
]);
|
|
293
307
|
|
|
294
308
|
const static_gridOptions = React.useMemo<GridOptions>(() => {
|
|
295
309
|
return { ...base_gridOptions, ...props.gridOptions, ...forcedOptions };
|
|
@@ -339,8 +353,8 @@ function DataGrid(props: DataGridProps) {
|
|
|
339
353
|
* @param props
|
|
340
354
|
* @returns
|
|
341
355
|
*/
|
|
342
|
-
function ApplyColumnData(props: any) {
|
|
343
|
-
const final_columns: MakeWriteable<
|
|
356
|
+
function ApplyColumnData(props: any): ColumnDefinition[] {
|
|
357
|
+
const final_columns: MakeWriteable<LooseColumnDefinition>[] = [];
|
|
344
358
|
let mcols = props.columns || [];
|
|
345
359
|
let mcolExts = props.columnExtensions || [];
|
|
346
360
|
let rightColumns = props.rightColumns || [];
|
|
@@ -420,6 +434,42 @@ function ApplyColumnData(props: any) {
|
|
|
420
434
|
}
|
|
421
435
|
}
|
|
422
436
|
}
|
|
437
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
438
|
+
const col = final_columns[index];
|
|
439
|
+
|
|
440
|
+
if (col.type) {
|
|
441
|
+
switch (col.type) {
|
|
442
|
+
case 'combo':
|
|
443
|
+
case 'select':
|
|
444
|
+
//@ts-ignore
|
|
445
|
+
col.editor = SelectEditor;
|
|
446
|
+
break;
|
|
447
|
+
//case 'number':
|
|
448
|
+
//case 'numberic':
|
|
449
|
+
// col.editor = NumericEditor;
|
|
450
|
+
// break;
|
|
451
|
+
//case 'truefalse':
|
|
452
|
+
//case 'bool':
|
|
453
|
+
// col.editor = BoolEditor;
|
|
454
|
+
// break;
|
|
455
|
+
}
|
|
456
|
+
delete col.type;
|
|
457
|
+
}
|
|
458
|
+
//@ts-ignore
|
|
459
|
+
if (!col.editorProps) col.editorProps = {};
|
|
460
|
+
if (col.items) {
|
|
461
|
+
//@ts-ignore
|
|
462
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
463
|
+
//@ts-ignore
|
|
464
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
465
|
+
//@ts-ignore
|
|
466
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
467
|
+
|
|
468
|
+
delete col.items;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/* -------------------------------------------------------------------------- */
|
|
423
473
|
if (Array.isArray(customColumns)) {
|
|
424
474
|
for (let index = 0; index < customColumns.length; index++) {
|
|
425
475
|
const r = customColumns[index];
|
|
@@ -435,34 +485,34 @@ function ApplyColumnData(props: any) {
|
|
|
435
485
|
/* ------------------------------ apply renames ----------------------------- */
|
|
436
486
|
for (let index = 0; index < final_columns.length; index++) {
|
|
437
487
|
const col = final_columns[index];
|
|
438
|
-
|
|
439
488
|
if (!col.name) {
|
|
440
489
|
col.name = get_col_name(col);
|
|
441
490
|
delete col.field;
|
|
442
491
|
delete col.key;
|
|
443
492
|
delete col.columnName;
|
|
444
493
|
}
|
|
445
|
-
//
|
|
446
|
-
if (col.type) {
|
|
447
|
-
col.editor = col.type;
|
|
448
|
-
delete col.type;
|
|
449
|
-
}
|
|
450
|
-
//
|
|
451
|
-
if (col.items) {
|
|
452
|
-
if (!col.editorParams) col.editorParams = { valuesLookup: true, allowEmpty: true };
|
|
453
|
-
col.editorParams.values = {};
|
|
454
|
-
for (let index = 0; index < col.items; index++) {
|
|
455
|
-
const ci = col.items[index];
|
|
456
|
-
col.editorParams.values[String(ci).toLowerCase()] = ci;
|
|
457
|
-
}
|
|
458
|
-
delete col.items;
|
|
459
|
-
}
|
|
460
494
|
}
|
|
461
495
|
/* -------------------------------------------------------------------------- */
|
|
462
|
-
|
|
496
|
+
console.log(final_columns);
|
|
463
497
|
return final_columns;
|
|
464
498
|
}
|
|
465
499
|
|
|
500
|
+
function to_datasource(arr: any[], idProperty: string) {
|
|
501
|
+
const res: any[] = [];
|
|
502
|
+
let index = 0;
|
|
503
|
+
if (Array.isArray(arr)) {
|
|
504
|
+
arr.map((s: any) => {
|
|
505
|
+
let elem = {};
|
|
506
|
+
elem[idProperty] = '_cid_' + index;
|
|
507
|
+
if (typeof s === 'object') elem = { ...elem, ...s };
|
|
508
|
+
else elem['label'] = s;
|
|
509
|
+
res.push(elem);
|
|
510
|
+
index++;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return res;
|
|
515
|
+
}
|
|
466
516
|
/**
|
|
467
517
|
* Gets name of a column from its column object
|
|
468
518
|
* @param obj
|