@azrico/reactgrid 1.3.38 → 1.3.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.3.38",
3
+ "version": "1.3.40",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
package/src/example.tsx CHANGED
@@ -30,13 +30,12 @@ const columns = [
30
30
  const editableColumns = ['job', 'age'];
31
31
 
32
32
  function getData(delta: any, max = 200) {
33
- const fd: any[] = [];
34
- console.log('Delta:', delta);
33
+ const fd: any[] = [];
35
34
  for (let index = 0; index < max; index++) {
36
35
  const currentObject = {
37
36
  __table_id: String(index),
38
37
  name: 'user-' + index,
39
- age: 20,
38
+ age: 5 + index,
40
39
  job: 'None',
41
40
  };
42
41
  if (delta[index] && typeof delta[index] === 'object') {
@@ -154,18 +154,20 @@ export function ApplyColumnData(column_data: any): ColumnDefinition[] {
154
154
  }
155
155
  for (let index = 0; index < final_columns.length; index++) {
156
156
  const col = final_columns[index];
157
- if (col.type) {
158
- switch (col.type) {
157
+ const coltype = col.type;
158
+ delete col.type;
159
+ if (coltype) {
160
+ switch (coltype) {
159
161
  case 'combo':
160
162
  case 'select':
161
163
  //@ts-ignore
162
164
  col.editor = SelectEditor;
163
165
  break;
164
- // case 'number':
165
- // case 'numberic':
166
- // //@ts-ignore
167
- // col.editor = NumericEditor;
168
- // break;
166
+ case 'int':
167
+ case 'number':
168
+ case 'numberic':
169
+ col.type = 'number';
170
+ break;
169
171
  case 'truefalse':
170
172
  case 'bool':
171
173
  case 'boolean':
@@ -174,7 +176,6 @@ export function ApplyColumnData(column_data: any): ColumnDefinition[] {
174
176
  break;
175
177
  }
176
178
  if (col.editable != false) col.editable = true;
177
- delete col.type;
178
179
  }
179
180
  //@ts-ignore
180
181
  if (!col.editorProps) col.editorProps = {};
@@ -177,7 +177,7 @@ export function AzGrid(props: AzGridProps) {
177
177
  props.editableColumns,
178
178
  props.columnExtensions,
179
179
  props.customColumns,
180
- ]);
180
+ ]);
181
181
  /* -------------------------------------------------------------------------- */
182
182
  /* Row changes */
183
183
  /* -------------------------------------------------------------------------- */
@@ -506,7 +506,6 @@ function DataGridSearchWrapper(props: DataGridWrapperProps) {
506
506
  []
507
507
  );
508
508
  React.useEffect(() => {
509
- set_search('');
510
509
  fn_eval(props.dataSource).then((r) => {
511
510
  currentDS.current = typeof r === 'object' ? r.data || r : r;
512
511
  searchIfNeeded();
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './src';
2
- import { AzGrid } from './src';
3
- export default AzGrid;
package/dist/index.js DELETED
@@ -1,21 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- export * from './views/DataGrid';
3
- export declare function ExampleGrid(): JSX.Element;
4
- export default ExampleGrid;
@@ -1,175 +0,0 @@
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: '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
- console.log('Delta:', delta);
47
- for (let index = 0; index < max; index++) {
48
- const currentObject = {
49
- __table_id: String(index),
50
- name: 'user-' + index,
51
- age: 20,
52
- job: 'None'
53
- };
54
- if (delta[index] && typeof delta[index] === 'object') {
55
- for (const key in delta[index]) {
56
- currentObject[key] = delta[index][key];
57
- }
58
- }
59
- const childrows = [];
60
- if (index % 5 == 0) {
61
- const sub_selfid = 's' + index;
62
- childrows.push({
63
- __table_id: sub_selfid,
64
- __parent__table_id: String(index),
65
- name: 'sub-' + index,
66
- age: 20
67
- });
68
- }
69
- currentObject['__children'] = childrows;
70
- fd.push(currentObject);
71
- }
72
- return fd;
73
- }
74
- function ExampleGrid() {
75
- const [ds_reset, set_ds_reset] = _react.default.useState(0);
76
- const [delta, set_delta] = _react.default.useState({});
77
- const [delayed_reload, set_delayed_reload] = _react.default.useState(false);
78
- const dataSource = _react.default.useMemo(() => getData(delta), []);
79
- // const dataSource = React.useCallback(
80
- // async (dt) => {
81
- // //console.log('Start loading');
82
- // return await new Promise((resolve) => {
83
- // setTimeout(() => {
84
- // resolve(getData(delta));
85
- // }, 1000);
86
- // });
87
- // },
88
- // [ds_reset, delta]
89
- // );
90
- // const details_dataSource = React.useCallback(
91
- // async (dt) => {
92
- // //console.log('Start loading');
93
- // return await new Promise((resolve) => {
94
- // setTimeout(() => {
95
- // resolve(getData(delta, 5));
96
- // }, 1000);
97
- // });
98
- // },
99
- // [ds_reset, delta]
100
- // );
101
- function onEditComplete(params) {
102
- const {
103
- value,
104
- columnId,
105
- rowId,
106
- ...rest
107
- } = params;
108
- let new_rd = delta[rowId];
109
- if (!new_rd) new_rd = {};
110
- new_rd[columnId] = value;
111
- set_delta(d => {
112
- return {
113
- ...d,
114
- [rowId]: new_rd
115
- };
116
- });
117
- }
118
- const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
119
- console.log('dbl', (rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
120
- }, []);
121
- const onRowClick = _react.default.useCallback((index, rowdata) => {
122
- //console.log(rowdata?.data || rowdata);
123
- }, []);
124
- _react.default.useEffect(() => {
125
- setTimeout(() => {
126
- set_delayed_reload(true);
127
- }, 2000);
128
- }, []);
129
- const customColumns = _react.default.useMemo(() => {
130
- if (!delayed_reload) return [];
131
- return [{
132
- name: 'name',
133
- render: r => r.value + '^'
134
- }];
135
- }, [delayed_reload]);
136
- const contextMenuItems = _react.default.useCallback(product => {
137
- return [{
138
- type: 'text',
139
- content: product.name
140
- }];
141
- }, []);
142
- return _react.default.createElement(_DataGrid.default, {
143
- delayedSize: true,
144
- dark: true,
145
- // details_dataSource={details_dataSource}
146
- dataSource: dataSource,
147
- details_columns: columns,
148
- onRowClick: onRowClick,
149
- onRowDoubleClick: onRowDoubleClick,
150
- allowChildRows: true,
151
- // onSelectionChange={onSelectionChange}
152
- // selected={selected}
153
- contextMenuItems: contextMenuItems,
154
- customColumns: customColumns,
155
- columns: columns,
156
- editableColumns: editableColumns,
157
- editable: true,
158
- onEditComplete: onEditComplete,
159
- advancedFilterFields: ['name'],
160
- // leftColumns={leftColumns}
161
- gridOptions: {
162
- // defaultFilterValue: filterValue,
163
- // remoteFilter: false,
164
- // multiSelect: true,
165
- // pagination: 'local',
166
- // defaultLimit: 100,
167
- // limit: 100,
168
- // pageSizes: [100],
169
- // rowIndexColumn: true,
170
- // checkboxColumn: true,
171
- }
172
- });
173
- }
174
- var _default = ExampleGrid;
175
- exports.default = _default;
@@ -1,29 +0,0 @@
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 {};
@@ -1,85 +0,0 @@
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 anyparentid = rows.find(r => get_parentId(r));
18
- const anyselfid = rows.find(r => get_selfId(r));
19
- if (!anyparentid || !anyselfid) return rows;
20
- const converted_rows = rows.filter(r => r != null).map(r => {
21
- return {
22
- parent: get_parentId(r),
23
- self: get_selfId(r),
24
- data: r
25
- };
26
- });
27
- const top_level_rows = converted_rows.filter(r => !r.parent);
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
- }
35
- }
36
- return top_level_rows.map(r => r.data);
37
- }
38
- function assign_children(row, all_rows) {
39
- const my_children = all_rows.filter(s => row.self == s.parent);
40
- if (my_children.length > 0) {
41
- //find children of my children:
42
- for (let index = 0; index < my_children.length; index++) {
43
- const child = my_children[index];
44
- assign_children(child, all_rows);
45
- }
46
- row.data.__children = my_children.map(r => r.data);
47
- } else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
48
- }
49
- class func_selection {
50
- static getVirtualElement(x = 0, y = 0) {
51
- const boundsRect = func_selection.generateGetBoundingClientRect(x, y);
52
- return {
53
- getBoundingClientRect: boundsRect
54
- };
55
- }
56
- static generateGetBoundingClientRect(x = 0, y = 0) {
57
- return () => ({
58
- width: 0,
59
- height: 0,
60
- top: y,
61
- right: x,
62
- bottom: y,
63
- left: x
64
- });
65
- }
66
- static get_selectedText() {
67
- var text = '';
68
- if (window.getSelection) {
69
- var _window$getSelection;
70
- text = (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString();
71
- } else if (document.selection && document.selection.type != 'Control') {
72
- var _document$selection$c;
73
- text = (_document$selection$c = document.selection.createRange()) === null || _document$selection$c === void 0 ? void 0 : _document$selection$c.text;
74
- }
75
- return text || '';
76
- }
77
- static has_selection() {
78
- const slct = window.getSelection();
79
- if (slct == null) return false;
80
- if (slct.type == null) return func_selection.get_selectedText().length !== 0;
81
- if (slct.type === 'Range') return true;
82
- return false;
83
- }
84
- }
85
- exports.func_selection = func_selection;
@@ -1,48 +0,0 @@
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;