@azrico/reactgrid 1.2.5 → 1.2.7
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 +27 -0
- package/dist/src/example.js +27 -8
- package/dist/src/func/{helpers.js → func_child.js} +11 -7
- package/dist/src/func/func_grid.d.ts +38 -0
- package/dist/src/func/func_grid.js +276 -0
- package/dist/src/index.js +0 -3
- package/dist/src/views/DataGrid.d.ts +5 -13
- package/dist/src/views/DataGrid.js +66 -285
- package/package.json +1 -1
- package/src/example.tsx +27 -8
- package/src/func/{helpers.ts → func_child.ts} +18 -10
- package/src/func/func_grid.ts +288 -0
- package/src/index.tsx +3 -3
- package/src/views/DataGrid.tsx +92 -300
- /package/dist/src/func/{helpers.d.ts → func_child.d.ts} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
### [1.2.7](https://github.com/Azrideus/azrico-reactgrid/compare/v1.2.6...v1.2.7) (2023-02-26)
|
|
6
|
+
|
|
7
|
+
### 1.2.6 (2023-02-26)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* added datasource Support ([4270ac1](https://github.com/Azrideus/azrico-reactgrid/commit/4270ac19623ef4c7404f0475825647c63ca98ffb))
|
|
13
|
+
* added inovua grid ([a178208](https://github.com/Azrideus/azrico-reactgrid/commit/a178208975212d16ce9feff359b09a6d8926b54d))
|
|
14
|
+
* added onLimitChange ([4b16681](https://github.com/Azrideus/azrico-reactgrid/commit/4b1668194776ebec51cdf9af0969132d5883d79a))
|
|
15
|
+
* added skip and limit values ([87a975c](https://github.com/Azrideus/azrico-reactgrid/commit/87a975cad9803b4d41d770c0758d6b4d09946a53))
|
|
16
|
+
* fixed dataSource ([ce5a4fe](https://github.com/Azrideus/azrico-reactgrid/commit/ce5a4fe09809aeddeeb0305d48b5294b1e9654b2))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* added get_col_name ([c7ff2da](https://github.com/Azrideus/azrico-reactgrid/commit/c7ff2daab8bf2ddf3c5fcbe6b47c7876d9ed9f88))
|
|
22
|
+
* added support for promise DS ([b684c26](https://github.com/Azrideus/azrico-reactgrid/commit/b684c2635d59f5d5dde129ed6425ce30abbeebed))
|
|
23
|
+
* coyp styles to dist ([23694f2](https://github.com/Azrideus/azrico-reactgrid/commit/23694f23634eb0b4038f399b1b2cd5c57992b64b))
|
|
24
|
+
* fixed fix_parent_child_relations ([f165179](https://github.com/Azrideus/azrico-reactgrid/commit/f1651797e2adfc2dfbe1905b8c858b150c842dfa))
|
|
25
|
+
* fixed package for publish ([95b8f46](https://github.com/Azrideus/azrico-reactgrid/commit/95b8f46e672174928aa4d8cd6c4924553eb025e5))
|
|
26
|
+
* no null rows ([e85511b](https://github.com/Azrideus/azrico-reactgrid/commit/e85511beb98c884a3820dfae7c2c57891910b6d1))
|
|
27
|
+
* removed extra styles from maincode ([7ee097e](https://github.com/Azrideus/azrico-reactgrid/commit/7ee097e4b7db1209490ce29bdb25fc605dfa7db3))
|
package/dist/src/example.js
CHANGED
|
@@ -26,7 +26,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
26
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
27
|
const columns = [{
|
|
28
28
|
name: 'name',
|
|
29
|
-
title: '
|
|
29
|
+
title: 'Name',
|
|
30
30
|
defaultFlex: 1
|
|
31
31
|
}, {
|
|
32
32
|
name: 'job',
|
|
@@ -41,10 +41,10 @@ const columns = [{
|
|
|
41
41
|
}];
|
|
42
42
|
const editableColumns = ['job', 'age'];
|
|
43
43
|
const contextMenuItems = ['test'];
|
|
44
|
-
function getData(delta) {
|
|
44
|
+
function getData(delta, max = 200) {
|
|
45
45
|
const fd = [];
|
|
46
46
|
console.log('Delta:', delta);
|
|
47
|
-
for (let index = 0; index <
|
|
47
|
+
for (let index = 0; index < max; index++) {
|
|
48
48
|
const currentObject = {
|
|
49
49
|
__table_id: String(index),
|
|
50
50
|
name: 'user-' + index,
|
|
@@ -82,6 +82,7 @@ function getData(delta) {
|
|
|
82
82
|
function ExampleGrid() {
|
|
83
83
|
const [ds_reset, set_ds_reset] = _react.default.useState(0);
|
|
84
84
|
const [delta, set_delta] = _react.default.useState({});
|
|
85
|
+
const [delayed_reload, set_delayed_reload] = _react.default.useState(false);
|
|
85
86
|
const dataSource = _react.default.useCallback(async dt => {
|
|
86
87
|
//console.log('Start loading');
|
|
87
88
|
return await new Promise(resolve => {
|
|
@@ -90,6 +91,14 @@ function ExampleGrid() {
|
|
|
90
91
|
}, 1000);
|
|
91
92
|
});
|
|
92
93
|
}, [ds_reset, delta]);
|
|
94
|
+
const details_dataSource = _react.default.useCallback(async dt => {
|
|
95
|
+
//console.log('Start loading');
|
|
96
|
+
return await new Promise(resolve => {
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
resolve(getData(delta, 5));
|
|
99
|
+
}, 1000);
|
|
100
|
+
});
|
|
101
|
+
}, [ds_reset, delta]);
|
|
93
102
|
function onEditComplete(params) {
|
|
94
103
|
const {
|
|
95
104
|
value,
|
|
@@ -113,20 +122,30 @@ function ExampleGrid() {
|
|
|
113
122
|
const onRowClick = _react.default.useCallback((index, rowdata) => {
|
|
114
123
|
//console.log(rowdata?.data || rowdata);
|
|
115
124
|
}, []);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
_react.default.useEffect(() => {
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
set_delayed_reload(true);
|
|
128
|
+
}, 2000);
|
|
129
|
+
}, []);
|
|
130
|
+
const customColumns = _react.default.useMemo(() => {
|
|
131
|
+
if (!delayed_reload) return [];
|
|
132
|
+
return [{
|
|
133
|
+
name: 'name',
|
|
134
|
+
render: r => r.value + '^'
|
|
135
|
+
}];
|
|
136
|
+
}, [delayed_reload]);
|
|
120
137
|
return _react.default.createElement(_DataGrid.default, {
|
|
121
138
|
dark: true,
|
|
122
139
|
delayedSize: true,
|
|
140
|
+
details_dataSource: details_dataSource,
|
|
141
|
+
details_columns: columns,
|
|
123
142
|
onRowClick: onRowClick,
|
|
124
143
|
onRowDoubleClick: onRowDoubleClick,
|
|
125
144
|
// allowChildRows
|
|
126
145
|
// onSelectionChange={onSelectionChange}
|
|
127
146
|
// selected={selected}
|
|
128
147
|
contextMenuItems: contextMenuItems,
|
|
129
|
-
|
|
148
|
+
customColumns: customColumns,
|
|
130
149
|
columns: columns,
|
|
131
150
|
editableColumns: editableColumns,
|
|
132
151
|
editable: true,
|
|
@@ -14,6 +14,9 @@ function get_selfId(obj) {
|
|
|
14
14
|
//given an array of rows, fixes parent,child relations
|
|
15
15
|
function fix_parent_child_relations(rows) {
|
|
16
16
|
if (!Array.isArray(rows)) rows = [];
|
|
17
|
+
const anyparentid = rows.find(r => get_parentId(r));
|
|
18
|
+
const anyselfid = rows.find(r => get_selfId(r));
|
|
19
|
+
if (!anyparentid || !anyselfid) return rows;
|
|
17
20
|
const converted_rows = rows.filter(r => r != null).map(r => {
|
|
18
21
|
return {
|
|
19
22
|
parent: get_parentId(r),
|
|
@@ -22,14 +25,15 @@ function fix_parent_child_relations(rows) {
|
|
|
22
25
|
};
|
|
23
26
|
});
|
|
24
27
|
const top_level_rows = converted_rows.filter(r => !r.parent);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const any_child = converted_rows.find(r => Boolean(r.parent));
|
|
29
|
+
if (any_child) {
|
|
30
|
+
//find children of top-level parents:
|
|
31
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
32
|
+
const mrow = top_level_rows[index];
|
|
33
|
+
assign_children(mrow, converted_rows);
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
//console.log(result);
|
|
32
|
-
return result;
|
|
36
|
+
return top_level_rows.map(r => r.data);
|
|
33
37
|
}
|
|
34
38
|
function assign_children(row, all_rows) {
|
|
35
39
|
const my_children = all_rows.filter(s => row.self == s.parent);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ColumnDefinition } from '../views/DataGrid';
|
|
2
|
+
export type MakeWriteable<Type> = {
|
|
3
|
+
-readonly [Key in keyof Type]: Type[Key];
|
|
4
|
+
};
|
|
5
|
+
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
6
|
+
export declare function ApplyDataSource(datasource: any, props: any): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* merges together all different props for columns
|
|
9
|
+
* to build a single final column data array
|
|
10
|
+
* @param column_data
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function ApplyColumnData(column_data: any): ColumnDefinition[];
|
|
14
|
+
export declare function to_datasource(arr: any[], idProperty: string, valueAsID?: boolean): any[];
|
|
15
|
+
/**
|
|
16
|
+
* Gets name of a column from its column object
|
|
17
|
+
* @param obj
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function get_col_name(obj: any): string;
|
|
21
|
+
/**
|
|
22
|
+
* Gets header of a column
|
|
23
|
+
* @param obj
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function get_col_header(obj: any): string;
|
|
27
|
+
/**
|
|
28
|
+
* Gets name of a column from its column object
|
|
29
|
+
* @param obj
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function get_row_id(obj: any): any;
|
|
33
|
+
/**
|
|
34
|
+
* Gets default activation key for grid plugin
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function get_default_key(): string;
|
|
38
|
+
export declare function validateCache(current: any, old: any, looseCheck?: boolean): boolean;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ApplyColumnData = ApplyColumnData;
|
|
7
|
+
exports.ApplyDataSource = ApplyDataSource;
|
|
8
|
+
exports.get_col_header = get_col_header;
|
|
9
|
+
exports.get_col_name = get_col_name;
|
|
10
|
+
exports.get_default_key = get_default_key;
|
|
11
|
+
exports.get_row_id = get_row_id;
|
|
12
|
+
exports.to_datasource = to_datasource;
|
|
13
|
+
exports.validateCache = validateCache;
|
|
14
|
+
var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
|
|
15
|
+
var _NumericEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/NumericEditor"));
|
|
16
|
+
var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
|
|
17
|
+
var _object = require("@azrico/object");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
const defaultColumnOptions = {
|
|
20
|
+
draggable: false,
|
|
21
|
+
lockable: false,
|
|
22
|
+
editable: false
|
|
23
|
+
};
|
|
24
|
+
async function ApplyDataSource(datasource, props) {
|
|
25
|
+
let result_data = undefined;
|
|
26
|
+
let isUsingCache = false;
|
|
27
|
+
const cacheInfo = {
|
|
28
|
+
ds: datasource,
|
|
29
|
+
skip: props.skip,
|
|
30
|
+
limit: props.limit
|
|
31
|
+
};
|
|
32
|
+
//check if we can used cached data
|
|
33
|
+
//if the datasource is changed since last render, we should invalidate cache
|
|
34
|
+
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
35
|
+
props.cached_data.current = undefined;
|
|
36
|
+
props.last_cache_info.current = cacheInfo;
|
|
37
|
+
}
|
|
38
|
+
if (props.cached_data.current) {
|
|
39
|
+
//cache is valid, use the cache
|
|
40
|
+
isUsingCache = true;
|
|
41
|
+
result_data = props.cached_data.current;
|
|
42
|
+
} else {
|
|
43
|
+
//cache is invalid, use the datasource again
|
|
44
|
+
isUsingCache = false;
|
|
45
|
+
if (typeof datasource === 'function') {
|
|
46
|
+
result_data = await datasource(props);
|
|
47
|
+
} else result_data = datasource;
|
|
48
|
+
}
|
|
49
|
+
//making sure the datasource is a valid object :
|
|
50
|
+
if (!result_data) result_data = [];
|
|
51
|
+
if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
|
|
52
|
+
data: result_data
|
|
53
|
+
};
|
|
54
|
+
if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
|
|
55
|
+
//no need to fix parent/child when using cache (it should be already fixed)
|
|
56
|
+
if (!isUsingCache && props.allowChildRows) if (!result_data.count)
|
|
57
|
+
//result_data.data = fix_parent_child_relations(result_data.data);
|
|
58
|
+
result_data.count = result_data.data.length;
|
|
59
|
+
//update cache
|
|
60
|
+
props.cached_data.current = result_data;
|
|
61
|
+
return result_data;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* merges together all different props for columns
|
|
65
|
+
* to build a single final column data array
|
|
66
|
+
* @param column_data
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
function ApplyColumnData(column_data) {
|
|
70
|
+
const final_columns = [];
|
|
71
|
+
if (!column_data) column_data = {};
|
|
72
|
+
if (Array.isArray(column_data)) column_data = {
|
|
73
|
+
columns: column_data
|
|
74
|
+
};
|
|
75
|
+
let mcols = column_data.columns || [];
|
|
76
|
+
let mcolExts = column_data.columnExtensions || [];
|
|
77
|
+
let rightColumns = column_data.rightColumns || [];
|
|
78
|
+
let leftColumns = column_data.leftColumns || [];
|
|
79
|
+
let editableColumns = column_data.editableColumns || [];
|
|
80
|
+
let customColumns = column_data.customColumns || [];
|
|
81
|
+
if (!Array.isArray(mcols)) return [];
|
|
82
|
+
/* ------------------------------- fix columns ------------------------------ */
|
|
83
|
+
mcols.map(r => {
|
|
84
|
+
if (r == null) return null;
|
|
85
|
+
if (typeof r === 'string') return {
|
|
86
|
+
field: r,
|
|
87
|
+
header: r
|
|
88
|
+
};
|
|
89
|
+
if (typeof r === 'object') {
|
|
90
|
+
let final_cl = {
|
|
91
|
+
name: get_col_name(r),
|
|
92
|
+
header: get_col_header(r),
|
|
93
|
+
width: r.width || undefined
|
|
94
|
+
};
|
|
95
|
+
final_cl = {
|
|
96
|
+
...defaultColumnOptions,
|
|
97
|
+
...r,
|
|
98
|
+
...final_cl
|
|
99
|
+
};
|
|
100
|
+
return final_cl;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}).forEach(r => {
|
|
104
|
+
if (r != null) final_columns.push(r);
|
|
105
|
+
});
|
|
106
|
+
/* ---------------------------- apply extensions ---------------------------- */
|
|
107
|
+
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
108
|
+
const ext = mcolExts[index];
|
|
109
|
+
const ext_cl = get_col_name(ext);
|
|
110
|
+
if (!ext_cl) {
|
|
111
|
+
console.warn('ColumnExtension must have a name');
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
|
|
115
|
+
if (mcol) {
|
|
116
|
+
for (const key in ext) {
|
|
117
|
+
if (!mcol[key] && key != 'name') mcol[key] = ext[key];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
|
|
121
|
+
}
|
|
122
|
+
/* ------------------------------- frozen cols ------------------------------ */
|
|
123
|
+
if (Array.isArray(leftColumns)) {
|
|
124
|
+
for (let index = 0; index < leftColumns.length; index++) {
|
|
125
|
+
const r = get_col_name(leftColumns[index]);
|
|
126
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
127
|
+
if (mcol) {
|
|
128
|
+
mcol.locked = 'start';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(rightColumns)) {
|
|
133
|
+
for (let index = 0; index < rightColumns.length; index++) {
|
|
134
|
+
const r = get_col_name(rightColumns[index]);
|
|
135
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
136
|
+
if (mcol) {
|
|
137
|
+
mcol.locked = 'end';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/* -------------------------------- ediatable ------------------------------- */
|
|
142
|
+
if (Array.isArray(editableColumns)) {
|
|
143
|
+
for (let index = 0; index < editableColumns.length; index++) {
|
|
144
|
+
const r = get_col_name(editableColumns[index]);
|
|
145
|
+
const mcol = final_columns.find(s => get_col_name(s) === r);
|
|
146
|
+
if (mcol) {
|
|
147
|
+
mcol.editable = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
152
|
+
const col = final_columns[index];
|
|
153
|
+
if (col.type) {
|
|
154
|
+
switch (col.type) {
|
|
155
|
+
case 'combo':
|
|
156
|
+
case 'select':
|
|
157
|
+
//@ts-ignore
|
|
158
|
+
col.editor = _SelectEditor.default;
|
|
159
|
+
break;
|
|
160
|
+
case 'number':
|
|
161
|
+
case 'numberic':
|
|
162
|
+
//@ts-ignore
|
|
163
|
+
col.editor = _NumericEditor.default;
|
|
164
|
+
break;
|
|
165
|
+
case 'truefalse':
|
|
166
|
+
case 'bool':
|
|
167
|
+
//@ts-ignore
|
|
168
|
+
col.editor = _BoolEditor.default;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (col.editable != false) col.editable = true;
|
|
172
|
+
delete col.type;
|
|
173
|
+
}
|
|
174
|
+
//@ts-ignore
|
|
175
|
+
if (!col.editorProps) col.editorProps = {};
|
|
176
|
+
if (col.items) {
|
|
177
|
+
//@ts-ignore
|
|
178
|
+
if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
|
|
179
|
+
//@ts-ignore
|
|
180
|
+
if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
|
|
181
|
+
//@ts-ignore
|
|
182
|
+
col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
|
|
183
|
+
delete col.items;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/* -------------------------------------------------------------------------- */
|
|
187
|
+
if (Array.isArray(customColumns)) {
|
|
188
|
+
for (let index = 0; index < customColumns.length; index++) {
|
|
189
|
+
const r = customColumns[index];
|
|
190
|
+
const rn = get_col_name(r);
|
|
191
|
+
const mcol = final_columns.find(s => get_col_name(s) === rn);
|
|
192
|
+
if (mcol) {
|
|
193
|
+
//@ts-ignore
|
|
194
|
+
mcol.render = r.render;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/* ------------------------------ apply renames ----------------------------- */
|
|
199
|
+
for (let index = 0; index < final_columns.length; index++) {
|
|
200
|
+
const col = final_columns[index];
|
|
201
|
+
if (!col.name) {
|
|
202
|
+
col.name = get_col_name(col);
|
|
203
|
+
delete col.field;
|
|
204
|
+
delete col.key;
|
|
205
|
+
delete col.columnName;
|
|
206
|
+
if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/* -------------------------------------------------------------------------- */
|
|
210
|
+
//console.log(final_columns);
|
|
211
|
+
return final_columns;
|
|
212
|
+
}
|
|
213
|
+
function to_datasource(arr, idProperty, valueAsID = true) {
|
|
214
|
+
const res = [];
|
|
215
|
+
let index = 0;
|
|
216
|
+
if (Array.isArray(arr)) {
|
|
217
|
+
arr.map(s => {
|
|
218
|
+
let elem = {};
|
|
219
|
+
if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
|
|
220
|
+
if (typeof s === 'object') elem = {
|
|
221
|
+
...elem,
|
|
222
|
+
...s
|
|
223
|
+
};else elem['label'] = s;
|
|
224
|
+
res.push(elem);
|
|
225
|
+
index++;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return res;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets name of a column from its column object
|
|
232
|
+
* @param obj
|
|
233
|
+
* @returns
|
|
234
|
+
*/
|
|
235
|
+
function get_col_name(obj) {
|
|
236
|
+
if (!obj) return '';
|
|
237
|
+
if (typeof obj == 'string') return obj;
|
|
238
|
+
if (typeof obj != 'object') return '';
|
|
239
|
+
return obj.name || obj.field || obj.key || obj.columnName || '';
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Gets header of a column
|
|
243
|
+
* @param obj
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
function get_col_header(obj) {
|
|
247
|
+
if (!obj) return '';
|
|
248
|
+
if (typeof obj == 'string') return obj;
|
|
249
|
+
if (typeof obj != 'object') return '';
|
|
250
|
+
return obj.header || obj.title || get_col_name(obj);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gets name of a column from its column object
|
|
254
|
+
* @param obj
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
function get_row_id(obj) {
|
|
258
|
+
if (!obj) return '-1';
|
|
259
|
+
if (typeof obj == 'string') return obj;
|
|
260
|
+
if (typeof obj != 'object') return '-1';
|
|
261
|
+
return obj.__table_id || obj.id || '-1';
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Gets default activation key for grid plugin
|
|
265
|
+
* @returns
|
|
266
|
+
*/
|
|
267
|
+
function get_default_key() {
|
|
268
|
+
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
269
|
+
}
|
|
270
|
+
//check if two cache objects are the same
|
|
271
|
+
function validateCache(current, old, looseCheck = false) {
|
|
272
|
+
if (!old || !(0, _object.object_equals)(current, old)) return false;
|
|
273
|
+
if (looseCheck) return true;
|
|
274
|
+
if (current.ds != old.ds) return false;
|
|
275
|
+
return true;
|
|
276
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -19,9 +19,6 @@ Object.keys(_DataGrid).forEach(function (key) {
|
|
|
19
19
|
});
|
|
20
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
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
|
-
// import ExampleGrid from './example';
|
|
23
|
-
// import React from 'react';
|
|
24
|
-
// import ReactDOM from 'react-dom/client';
|
|
25
22
|
/* -------------------------------------------------------------------------- */
|
|
26
23
|
var _default = _DataGrid.default; // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
|
|
27
24
|
// root.render(<ExampleGrid />);
|
|
@@ -5,7 +5,7 @@ import '../themes/base_styles.css';
|
|
|
5
5
|
import '../themes/grid.css';
|
|
6
6
|
import { ConvertableToMenuItem } from '@azrico/controls';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
|
|
8
|
+
import { TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeFilterValue, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection } from '@inovua/reactdatagrid-community/types';
|
|
9
9
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
10
10
|
export type ColumnDefinition = TypeColumn;
|
|
11
11
|
export type CellDefinition = any;
|
|
@@ -14,6 +14,7 @@ export type RowProps = TypeRowProps;
|
|
|
14
14
|
export type RowSelectionValue = TypeRowSelection;
|
|
15
15
|
export type DataRowDefinition = any;
|
|
16
16
|
export type FilterTypes = TypeFilterTypes;
|
|
17
|
+
export type FilterValues = TypeFilterValue;
|
|
17
18
|
export type DataSourceDefinition = TypeDataSource;
|
|
18
19
|
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
19
20
|
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
@@ -36,6 +37,9 @@ type customColumnData = {
|
|
|
36
37
|
type GridOptions = Partial<TypeDataGridProps>;
|
|
37
38
|
export type AzGridProps = {
|
|
38
39
|
dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
40
|
+
details_dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
|
|
41
|
+
details_columns?: LooseColumnDefinition[];
|
|
42
|
+
details_filter?: FilterValues;
|
|
39
43
|
licenseKey?: string;
|
|
40
44
|
gridRef?: any;
|
|
41
45
|
gridOptions?: GridOptions;
|
|
@@ -66,16 +70,4 @@ export type AzGridProps = {
|
|
|
66
70
|
className?: string;
|
|
67
71
|
};
|
|
68
72
|
export declare function AzGrid(props: AzGridProps): JSX.Element;
|
|
69
|
-
/**
|
|
70
|
-
* Gets name of a column from its column object
|
|
71
|
-
* @param obj
|
|
72
|
-
* @returns
|
|
73
|
-
*/
|
|
74
|
-
export declare function get_col_name(obj: any): string;
|
|
75
|
-
/**
|
|
76
|
-
* Gets header of a column
|
|
77
|
-
* @param obj
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
export declare function get_col_header(obj: any): string;
|
|
81
73
|
export default AzGrid;
|