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