@azrico/reactgrid 1.3.40 → 1.3.42

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.
@@ -0,0 +1,3 @@
1
+ export * from './src';
2
+ import { AzGrid } from './src';
3
+ export default AzGrid;
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
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 = exports.default = _src.AzGrid;
@@ -0,0 +1,4 @@
1
+ export * from './views/DataGrid';
2
+ import React from 'react';
3
+ export declare function ExampleGrid(): React.JSX.Element;
4
+ export default ExampleGrid;
@@ -0,0 +1,173 @@
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(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
+ const columns = [{
28
+ name: 'name',
29
+ title: 'Name',
30
+ defaultFlex: 1
31
+ }, {
32
+ name: 'job',
33
+ title: 'Job',
34
+ type: 'combo',
35
+ items: ['None', 'Engineer', 'Doctor'],
36
+ defaultFlex: 1
37
+ }, {
38
+ name: 'age',
39
+ title: 'Age',
40
+ type: 'number',
41
+ defaultFlex: 1
42
+ }];
43
+ const editableColumns = ['job', 'age'];
44
+ function getData(delta, max = 200) {
45
+ const fd = [];
46
+ for (let index = 0; index < max; index++) {
47
+ const currentObject = {
48
+ __table_id: String(index),
49
+ name: 'user-' + index,
50
+ age: 5 + index,
51
+ job: 'None'
52
+ };
53
+ if (delta[index] && typeof delta[index] === 'object') {
54
+ for (const key in delta[index]) {
55
+ currentObject[key] = delta[index][key];
56
+ }
57
+ }
58
+ const childrows = [];
59
+ if (index % 5 == 0) {
60
+ const sub_selfid = 's' + index;
61
+ childrows.push({
62
+ __table_id: sub_selfid,
63
+ __parent__table_id: String(index),
64
+ name: 'sub-' + index,
65
+ age: 20
66
+ });
67
+ }
68
+ currentObject['__children'] = childrows;
69
+ fd.push(currentObject);
70
+ }
71
+ return fd;
72
+ }
73
+ function ExampleGrid() {
74
+ const [ds_reset, set_ds_reset] = _react.default.useState(0);
75
+ const [delta, set_delta] = _react.default.useState({});
76
+ const [delayed_reload, set_delayed_reload] = _react.default.useState(false);
77
+ const dataSource = _react.default.useMemo(() => getData(delta), []);
78
+ // const dataSource = React.useCallback(
79
+ // async (dt) => {
80
+ // //console.log('Start loading');
81
+ // return await new Promise((resolve) => {
82
+ // setTimeout(() => {
83
+ // resolve(getData(delta));
84
+ // }, 1000);
85
+ // });
86
+ // },
87
+ // [ds_reset, delta]
88
+ // );
89
+ // const details_dataSource = React.useCallback(
90
+ // async (dt) => {
91
+ // //console.log('Start loading');
92
+ // return await new Promise((resolve) => {
93
+ // setTimeout(() => {
94
+ // resolve(getData(delta, 5));
95
+ // }, 1000);
96
+ // });
97
+ // },
98
+ // [ds_reset, delta]
99
+ // );
100
+ function onEditComplete(params) {
101
+ const {
102
+ value,
103
+ columnId,
104
+ rowId,
105
+ ...rest
106
+ } = params;
107
+ let new_rd = delta[rowId];
108
+ if (!new_rd) new_rd = {};
109
+ new_rd[columnId] = value;
110
+ set_delta(d => {
111
+ return {
112
+ ...d,
113
+ [rowId]: new_rd
114
+ };
115
+ });
116
+ }
117
+ const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
118
+ console.log('dbl', (rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
119
+ }, []);
120
+ const onRowClick = _react.default.useCallback((index, rowdata) => {
121
+ //console.log(rowdata?.data || rowdata);
122
+ }, []);
123
+ _react.default.useEffect(() => {
124
+ setTimeout(() => {
125
+ set_delayed_reload(true);
126
+ }, 2000);
127
+ }, []);
128
+ const customColumns = _react.default.useMemo(() => {
129
+ if (!delayed_reload) return [];
130
+ return [{
131
+ name: 'name',
132
+ render: r => r.value + '^'
133
+ }];
134
+ }, [delayed_reload]);
135
+ const contextMenuItems = _react.default.useCallback(product => {
136
+ return [{
137
+ type: 'text',
138
+ content: product.name
139
+ }];
140
+ }, []);
141
+ return _react.default.createElement(_DataGrid.default, {
142
+ delayedSize: true,
143
+ dark: true,
144
+ // details_dataSource={details_dataSource}
145
+ dataSource: dataSource,
146
+ details_columns: columns,
147
+ onRowClick: onRowClick,
148
+ onRowDoubleClick: onRowDoubleClick,
149
+ allowChildRows: true,
150
+ // onSelectionChange={onSelectionChange}
151
+ // selected={selected}
152
+ contextMenuItems: contextMenuItems,
153
+ customColumns: customColumns,
154
+ columns: columns,
155
+ editableColumns: editableColumns,
156
+ editable: true,
157
+ onEditComplete: onEditComplete,
158
+ advancedFilterFields: ['name'],
159
+ // leftColumns={leftColumns}
160
+ gridOptions: {
161
+ // defaultFilterValue: filterValue,
162
+ // remoteFilter: false,
163
+ // multiSelect: true,
164
+ // pagination: 'local',
165
+ // defaultLimit: 100,
166
+ // limit: 100,
167
+ // pageSizes: [100],
168
+ // rowIndexColumn: true,
169
+ // checkboxColumn: true,
170
+ }
171
+ });
172
+ }
173
+ var _default = exports.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,87 @@
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
+ var _ref, _obj$__parent__table_;
10
+ return (_ref = (_obj$__parent__table_ = obj.__parent__table_id) !== null && _obj$__parent__table_ !== void 0 ? _obj$__parent__table_ : obj.parent) !== null && _ref !== void 0 ? _ref : obj.parentid;
11
+ }
12
+ function get_selfId(obj) {
13
+ var _obj$__table_id;
14
+ return (_obj$__table_id = obj.__table_id) !== null && _obj$__table_id !== void 0 ? _obj$__table_id : obj._id;
15
+ }
16
+ //given an array of rows, fixes parent,child relations
17
+ function fix_parent_child_relations(rows) {
18
+ if (!Array.isArray(rows)) rows = [];
19
+ const anyparentid = rows.find(r => get_parentId(r));
20
+ const anyselfid = rows.find(r => get_selfId(r));
21
+ if (!anyparentid || !anyselfid) return rows;
22
+ const converted_rows = rows.filter(r => r != null).map(r => {
23
+ return {
24
+ parent: get_parentId(r),
25
+ self: get_selfId(r),
26
+ data: r
27
+ };
28
+ });
29
+ const top_level_rows = converted_rows.filter(r => !r.parent);
30
+ const any_child = converted_rows.find(r => Boolean(r.parent));
31
+ if (any_child) {
32
+ //find children of top-level parents:
33
+ for (let index = 0; index < top_level_rows.length; index++) {
34
+ const mrow = top_level_rows[index];
35
+ assign_children(mrow, converted_rows);
36
+ }
37
+ }
38
+ return top_level_rows.map(r => r.data);
39
+ }
40
+ function assign_children(row, all_rows) {
41
+ const my_children = all_rows.filter(s => row.self == s.parent);
42
+ if (my_children.length > 0) {
43
+ //find children of my children:
44
+ for (let index = 0; index < my_children.length; index++) {
45
+ const child = my_children[index];
46
+ assign_children(child, all_rows);
47
+ }
48
+ row.data.__children = my_children.map(r => r.data);
49
+ } else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
50
+ }
51
+ class func_selection {
52
+ static getVirtualElement(x = 0, y = 0) {
53
+ const boundsRect = func_selection.generateGetBoundingClientRect(x, y);
54
+ return {
55
+ getBoundingClientRect: boundsRect
56
+ };
57
+ }
58
+ static generateGetBoundingClientRect(x = 0, y = 0) {
59
+ return () => ({
60
+ width: 0,
61
+ height: 0,
62
+ top: y,
63
+ right: x,
64
+ bottom: y,
65
+ left: x
66
+ });
67
+ }
68
+ static get_selectedText() {
69
+ var text = '';
70
+ if (window.getSelection) {
71
+ var _window$getSelection;
72
+ text = (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString();
73
+ } else if (document.selection && document.selection.type != 'Control') {
74
+ var _document$selection$c;
75
+ text = (_document$selection$c = document.selection.createRange()) === null || _document$selection$c === void 0 ? void 0 : _document$selection$c.text;
76
+ }
77
+ return text || '';
78
+ }
79
+ static has_selection() {
80
+ const slct = window.getSelection();
81
+ if (slct == null) return false;
82
+ if (slct.type == null) return func_selection.get_selectedText().length !== 0;
83
+ if (slct.type === 'Range') return true;
84
+ return false;
85
+ }
86
+ }
87
+ exports.func_selection = func_selection;
@@ -0,0 +1,48 @@
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
+ export declare function set_row_id(obj: any, val: undefined | string): any;
34
+ /**
35
+ * Gets default activation key for grid plugin
36
+ * THIS KEY IS FOR DEBUGGING PURPOSE ONLY.
37
+ * PROVIDE YOUR OWN KEY
38
+ * @returns
39
+ */
40
+ export declare function get_default_key(): string;
41
+ export declare function validateCache(current: any, old: any, looseCheck?: boolean): boolean;
42
+ /**
43
+ * find the real index of the given row data
44
+ * sometimes when we scroll the rowData prop becomes invalid
45
+ * but we can manually find the correct data by reading the id from clicked item's Html props
46
+ * @param view
47
+ */
48
+ export declare function find_realData(alldata: any[], view: any, def?: undefined): any;
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ApplyColumnData = ApplyColumnData;
7
+ exports.ApplyDataSource = ApplyDataSource;
8
+ exports.find_realData = find_realData;
9
+ exports.get_col_header = get_col_header;
10
+ exports.get_col_name = get_col_name;
11
+ exports.get_default_key = get_default_key;
12
+ exports.get_row_id = get_row_id;
13
+ exports.set_row_id = set_row_id;
14
+ exports.to_datasource = to_datasource;
15
+ exports.validateCache = validateCache;
16
+ var _BoolEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/BoolEditor"));
17
+ var _SelectEditor = _interopRequireDefault(require("@inovua/reactdatagrid-community/SelectEditor"));
18
+ var _func_child = require("./func_child");
19
+ var _object = require("@azrico/object");
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ // import NumericEditor from '@inovua/reactdatagrid-community/NumericEditor';
22
+
23
+ const defaultColumnOptions = {
24
+ draggable: false,
25
+ lockable: false,
26
+ editable: false
27
+ };
28
+ async function ApplyDataSource(datasource, props) {
29
+ let result_data = undefined;
30
+ let isUsingCache = false;
31
+ const cacheInfo = {
32
+ ds: datasource,
33
+ skip: props.skip,
34
+ limit: props.limit
35
+ };
36
+ //check if we can used cached data
37
+ //if the datasource is changed since last render, we should invalidate cache
38
+ if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
39
+ props.cached_data.current = undefined;
40
+ props.last_cache_info.current = cacheInfo;
41
+ }
42
+ if (props.cached_data.current) {
43
+ //cache is valid, use the cache
44
+ isUsingCache = true;
45
+ result_data = props.cached_data.current;
46
+ } else {
47
+ //cache is invalid, use the datasource again
48
+ isUsingCache = false;
49
+ if (typeof datasource === 'function') {
50
+ result_data = await datasource(props);
51
+ } else result_data = datasource;
52
+ }
53
+ //making sure the datasource is a valid object :
54
+ if (!result_data) result_data = [];
55
+ if (Array.isArray(result_data) || typeof result_data !== 'object') result_data = {
56
+ data: result_data
57
+ };
58
+ if (!Array.isArray(result_data.data)) result_data.data = [result_data.data];
59
+ //no need to fix parent/child when using cache (it should be already fixed)
60
+ if (!isUsingCache && props.allowChildRows) {
61
+ result_data.data = (0, _func_child.fix_parent_child_relations)(result_data.data);
62
+ }
63
+ if (!result_data.count) {
64
+ result_data.count = result_data.data.length;
65
+ }
66
+ //update cache
67
+ props.cached_data.current = result_data;
68
+ return result_data;
69
+ }
70
+ /**
71
+ * merges together all different props for columns
72
+ * to build a single final column data array
73
+ * @param column_data
74
+ * @returns
75
+ */
76
+ function ApplyColumnData(column_data) {
77
+ const final_columns = [];
78
+ if (!column_data) column_data = {};
79
+ if (Array.isArray(column_data)) column_data = {
80
+ columns: column_data
81
+ };
82
+ let mcols = column_data.columns || [];
83
+ let mcolExts = column_data.columnExtensions || [];
84
+ let rightColumns = column_data.rightColumns || [];
85
+ let leftColumns = column_data.leftColumns || [];
86
+ let editableColumns = column_data.editableColumns || [];
87
+ let customColumns = column_data.customColumns || [];
88
+ if (!Array.isArray(mcols)) return [];
89
+ /* ------------------------------- fix columns ------------------------------ */
90
+ mcols.map(r => {
91
+ if (r == null) return null;
92
+ if (typeof r === 'string') return {
93
+ field: r,
94
+ header: r
95
+ };
96
+ if (typeof r === 'object') {
97
+ let final_cl = {
98
+ name: get_col_name(r),
99
+ header: get_col_header(r),
100
+ width: r.width || undefined
101
+ };
102
+ final_cl = {
103
+ ...defaultColumnOptions,
104
+ ...r,
105
+ ...final_cl
106
+ };
107
+ return final_cl;
108
+ }
109
+ return null;
110
+ }).forEach(r => {
111
+ if (r != null) final_columns.push(r);
112
+ });
113
+ /* ---------------------------- apply extensions ---------------------------- */
114
+ if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
115
+ const ext = mcolExts[index];
116
+ const ext_cl = get_col_name(ext);
117
+ if (!ext_cl) {
118
+ console.warn('ColumnExtension must have a name');
119
+ continue;
120
+ }
121
+ const mcol = final_columns.find(s => get_col_name(s) === ext_cl);
122
+ if (mcol) {
123
+ for (const key in ext) {
124
+ if (!mcol[key] && key != 'name') mcol[key] = ext[key];
125
+ }
126
+ }
127
+ // if (ext.widthGrow) mcol.widthGrow = ext.widthGrow;
128
+ }
129
+ /* ------------------------------- frozen cols ------------------------------ */
130
+ if (Array.isArray(leftColumns)) {
131
+ for (let index = 0; index < leftColumns.length; index++) {
132
+ const r = get_col_name(leftColumns[index]);
133
+ const mcol = final_columns.find(s => get_col_name(s) === r);
134
+ if (mcol) {
135
+ mcol.locked = 'start';
136
+ }
137
+ }
138
+ }
139
+ if (Array.isArray(rightColumns)) {
140
+ for (let index = 0; index < rightColumns.length; index++) {
141
+ const r = get_col_name(rightColumns[index]);
142
+ const mcol = final_columns.find(s => get_col_name(s) === r);
143
+ if (mcol) {
144
+ mcol.locked = 'end';
145
+ }
146
+ }
147
+ }
148
+ /* -------------------------------- ediatable ------------------------------- */
149
+ if (Array.isArray(editableColumns)) {
150
+ for (let index = 0; index < editableColumns.length; index++) {
151
+ const r = get_col_name(editableColumns[index]);
152
+ const mcol = final_columns.find(s => get_col_name(s) === r);
153
+ if (mcol) {
154
+ mcol.editable = true;
155
+ }
156
+ }
157
+ }
158
+ for (let index = 0; index < final_columns.length; index++) {
159
+ const col = final_columns[index];
160
+ const coltype = col.type;
161
+ delete col.type;
162
+ if (coltype) {
163
+ switch (coltype) {
164
+ case 'combo':
165
+ case 'select':
166
+ //@ts-ignore
167
+ col.editor = _SelectEditor.default;
168
+ break;
169
+ case 'int':
170
+ case 'number':
171
+ case 'numberic':
172
+ col.type = 'number';
173
+ break;
174
+ case 'truefalse':
175
+ case 'bool':
176
+ case 'boolean':
177
+ //@ts-ignore
178
+ col.editor = _BoolEditor.default;
179
+ break;
180
+ }
181
+ if (col.editable != false) col.editable = true;
182
+ }
183
+ //@ts-ignore
184
+ if (!col.editorProps) col.editorProps = {};
185
+ if (col.items) {
186
+ //@ts-ignore
187
+ if (!col.editorProps.idProperty) col.editorProps.idProperty = 'id';
188
+ //@ts-ignore
189
+ if (!col.editorProps.collapseOnSelect) col.editorProps.collapseOnSelect = true;
190
+ //@ts-ignore
191
+ col.editorProps.dataSource = to_datasource(col.items, col.editorProps.idProperty);
192
+ delete col.items;
193
+ }
194
+ }
195
+ /* -------------------------------------------------------------------------- */
196
+ if (Array.isArray(customColumns)) {
197
+ for (let index = 0; index < customColumns.length; index++) {
198
+ const r = customColumns[index];
199
+ const rn = get_col_name(r);
200
+ const mcol = final_columns.find(s => get_col_name(s) === rn);
201
+ if (mcol) {
202
+ //@ts-ignore
203
+ mcol.render = r.render;
204
+ }
205
+ }
206
+ }
207
+ /* ------------------------------ apply renames ----------------------------- */
208
+ for (let index = 0; index < final_columns.length; index++) {
209
+ const col = final_columns[index];
210
+ if (!col.name) {
211
+ col.name = get_col_name(col);
212
+ delete col.field;
213
+ delete col.key;
214
+ delete col.columnName;
215
+ if (col.flex && !col.defaultFlex) col.defaultFlex = col.flex;
216
+ }
217
+ }
218
+ /* -------------------------------------------------------------------------- */
219
+ //console.log(final_columns);
220
+ return final_columns;
221
+ }
222
+ function to_datasource(arr, idProperty, valueAsID = true) {
223
+ const res = [];
224
+ let index = 0;
225
+ if (Array.isArray(arr)) {
226
+ arr.map(s => {
227
+ let elem = {};
228
+ if (valueAsID) elem[idProperty] = String(s).toLowerCase();else elem[idProperty] = '_cid_' + index;
229
+ if (typeof s === 'object') elem = {
230
+ ...elem,
231
+ ...s
232
+ };else elem['label'] = s;
233
+ res.push(elem);
234
+ index++;
235
+ });
236
+ }
237
+ return res;
238
+ }
239
+ /**
240
+ * Gets name of a column from its column object
241
+ * @param obj
242
+ * @returns
243
+ */
244
+ function get_col_name(obj) {
245
+ if (!obj) return '';
246
+ if (typeof obj == 'string') return obj;
247
+ if (typeof obj != 'object') return '';
248
+ return obj.name || obj.field || obj.key || obj.columnName || '';
249
+ }
250
+ /**
251
+ * Gets header of a column
252
+ * @param obj
253
+ * @returns
254
+ */
255
+ function get_col_header(obj) {
256
+ if (!obj) return '';
257
+ if (typeof obj == 'string') return obj;
258
+ if (typeof obj != 'object') return '';
259
+ return obj.header || obj.title || get_col_name(obj);
260
+ }
261
+ /**
262
+ * Gets name of a column from its column object
263
+ * @param obj
264
+ * @returns
265
+ */
266
+ function get_row_id(obj) {
267
+ if (typeof obj === 'string') return obj;
268
+ if (typeof obj !== 'object' || !obj) return undefined;
269
+ return obj.__table_id || obj.id || undefined;
270
+ }
271
+ function set_row_id(obj, val) {
272
+ if (typeof obj != 'object') return false;
273
+ if (val === undefined) delete obj.__table_id;else obj.__table_id = val;
274
+ return obj.__table_id;
275
+ }
276
+ /**
277
+ * Gets default activation key for grid plugin
278
+ * THIS KEY IS FOR DEBUGGING PURPOSE ONLY.
279
+ * PROVIDE YOUR OWN KEY
280
+ * @returns
281
+ */
282
+ function get_default_key() {
283
+ return 'ExpiryDate=2999-01-01,Z=1040577552';
284
+ }
285
+ //check if two cache objects are the same
286
+ function validateCache(current, old, looseCheck = false) {
287
+ if (!old || !(0, _object.object_equals)(current, old)) return false;
288
+ if (looseCheck) return true;
289
+ if (current.ds != old.ds) return false;
290
+ return true;
291
+ }
292
+ /**
293
+ * find the real index of the given row data
294
+ * @param view
295
+ */
296
+ function find_realIndex(view) {
297
+ let current_parent = view;
298
+ for (let index = 0; index < 3; index++) {
299
+ var _current_parent;
300
+ current_parent = current_parent.parentElement;
301
+ const dataId = (_current_parent = current_parent) === null || _current_parent === void 0 ? void 0 : _current_parent.getAttribute('data-row-id');
302
+ if (dataId) return dataId;
303
+ }
304
+ return -1;
305
+ }
306
+ /**
307
+ * find the real index of the given row data
308
+ * sometimes when we scroll the rowData prop becomes invalid
309
+ * but we can manually find the correct data by reading the id from clicked item's Html props
310
+ * @param view
311
+ */
312
+ function find_realData(alldata, view, def = undefined) {
313
+ if (!Array.isArray(alldata)) return def;
314
+ const rid = find_realIndex(view);
315
+ if (rid === -1) return def;
316
+ // console.log('dataSource', alldata);
317
+ return alldata.find(s => get_row_id(s) === rid);
318
+ }
@@ -0,0 +1,4 @@
1
+ export * from './views/DataGrid';
2
+ export { get_row_id, set_row_id, get_col_name, get_col_header } from './func/func_grid';
3
+ import AzGrid from './views/DataGrid';
4
+ export default AzGrid;