@azrico/reactgrid 1.0.20 → 1.0.22

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.
@@ -78,24 +78,25 @@ function getData() {
78
78
  return fd;
79
79
  }
80
80
  function ExampleGrid() {
81
- const renderContactsGrid = ({
82
- data
83
- }) => {
84
- return _react.default.createElement("div", null, _react.default.createElement("div", null, 'Test'));
85
- };
86
81
  const [selected, setSelected] = _react.default.useState(null);
87
- const [rows, set_rows] = _react.default.useState([]);
88
82
  const onSelectionChange = _react.default.useCallback(({
89
83
  selected
90
84
  }) => {
91
85
  setSelected(selected);
92
86
  }, []);
93
- _react.default.useEffect(() => {
94
- setTimeout(() => {
95
- set_rows(getData());
96
- }, 1000);
87
+ const dataSource = _react.default.useCallback(async dt => {
88
+ console.log('Start loading');
89
+ return await new Promise(resolve => {
90
+ setTimeout(() => {
91
+ console.log('end loading');
92
+ resolve({
93
+ data: getData(),
94
+ count: 999
95
+ });
96
+ }, 1000);
97
+ });
97
98
  }, []);
98
- return _react.default.createElement(_DataGrid.default, {
99
+ return _react.default.createElement("div", null, _react.default.createElement(_DataGrid.default, {
99
100
  dark: true,
100
101
  allowChildRows: true,
101
102
  onSelectionChange: onSelectionChange,
@@ -103,13 +104,35 @@ function ExampleGrid() {
103
104
  contextMenuItems: contextMenuItems,
104
105
  customColumns: customColumns,
105
106
  columns: columns,
106
- rows: rows,
107
107
  leftColumns: leftColumns,
108
108
  gridOptions: {
109
+ pagination: 'remote',
110
+ defaultLimit: 100,
111
+ limit: 100,
112
+ pageSizes: [100],
109
113
  rowIndexColumn: true,
110
114
  checkboxColumn: true
111
- }
112
- });
115
+ },
116
+ dataSource: dataSource
117
+ }), _react.default.createElement(_DataGrid.default, {
118
+ dark: true,
119
+ allowChildRows: true,
120
+ onSelectionChange: onSelectionChange,
121
+ selected: selected,
122
+ contextMenuItems: contextMenuItems,
123
+ customColumns: customColumns,
124
+ columns: columns,
125
+ leftColumns: leftColumns,
126
+ gridOptions: {
127
+ pagination: 'remote',
128
+ defaultLimit: 100,
129
+ limit: 100,
130
+ pageSizes: [100],
131
+ rowIndexColumn: true,
132
+ checkboxColumn: true
133
+ },
134
+ dataSource: dataSource
135
+ }));
113
136
  }
114
137
  var _default = ExampleGrid;
115
138
  exports.default = _default;
package/dist/src/index.js CHANGED
@@ -17,21 +17,8 @@ Object.keys(_DataGrid).forEach(function (key) {
17
17
  }
18
18
  });
19
19
  });
20
- var _example = _interopRequireDefault(require("./example"));
21
- var _react = _interopRequireDefault(require("react"));
22
- var _client = _interopRequireDefault(require("react-dom/client"));
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
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); }
25
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; }
26
- /* -------------------------------------------------------------------------- */
27
- var _default = _DataGrid.default;
28
- exports.default = _default;
29
- if (process.env.NODE_ENV === 'production') {
30
- // set production urls
31
- // enable sentry
32
- } else if (process.env.NODE_ENV === 'development') {
33
- const root = _client.default.createRoot(document.getElementById('root'));
34
- root.render(_react.default.createElement(_example.default, null));
35
- } else {
36
- // set defaults
37
- }
22
+ var _default = _DataGrid.default; // const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
23
+ // root.render(<ExampleGrid />);
24
+ exports.default = _default;
@@ -33,7 +33,7 @@ type customColumnData = {
33
33
  type GridOptions = Partial<TypeDataGridProps>;
34
34
  export type AzGridProps = {
35
35
  columns?: columnOrString[];
36
- rows?: any[] | ((args: any) => any[] | Promise<any[]>);
36
+ dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
37
37
  licenseKey?: string;
38
38
  gridOptions?: GridOptions;
39
39
  columnExtensions?: Array<{
@@ -43,12 +43,26 @@ function AzGrid(props) {
43
43
  /* Row changes */
44
44
  /* -------------------------------------------------------------------------- */
45
45
  const dataSource = _react.default.useCallback(async dt => {
46
- let result_rows = typeof props.rows === 'function' ? await props.rows(dt) : props.rows;
47
- if (result_rows == null) return [];
46
+ let result_rows = [];
47
+ let result_data = undefined;
48
+ if (typeof props.dataSource === 'function') {
49
+ result_data = await props.dataSource(dt);
50
+ if (typeof result_data === 'object') {
51
+ result_rows = result_data.data;
52
+ } else result_rows = result_data;
53
+ } else {
54
+ result_rows = props.dataSource || [];
55
+ }
48
56
  if (!Array.isArray(result_rows)) result_rows = [result_rows];
49
57
  if (props.allowChildRows) result_rows = (0, _helpers.fix_parent_child_relations)(result_rows);
58
+ if (result_data && typeof result_data === 'object') {
59
+ return {
60
+ ...result_data,
61
+ data: result_rows
62
+ };
63
+ }
50
64
  return result_rows;
51
- }, [props.rows]);
65
+ }, [props.dataSource]);
52
66
  return _react.default.createElement(DataGrid, {
53
67
  ...props,
54
68
  columns: cached_columns,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/reactgrid",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "main": "dist/index.js",
5
5
  "description": "React Datagrid",
6
6
  "author": "Azrideus <MehrdadTavangar@gmail.com>",
@@ -32,7 +32,7 @@
32
32
  "@azrico/controls": "1.3.0",
33
33
  "@emotion/react": "^11.9.3",
34
34
  "@emotion/styled": "^11.9.3",
35
- "@inovua/reactdatagrid-enterprise": "^5.6.1",
35
+ "@inovua/reactdatagrid-enterprise": "^5.8.0",
36
36
  "clsx": "^1.2.1",
37
37
  "react": "^18.2.0",
38
38
  "react-resize-detector": "^7.1.2"
package/src/example.tsx CHANGED
@@ -28,10 +28,20 @@ function getData() {
28
28
  fd.push({ __table_id: String(index), username: 'user-' + index, age: 20 });
29
29
  if (index % 5 == 0) {
30
30
  const sub_selfid = 's' + index;
31
- fd.push({ __table_id: sub_selfid, __parent__table_id: String(index), username: 'sub-' + index, age: 20 });
31
+ fd.push({
32
+ __table_id: sub_selfid,
33
+ __parent__table_id: String(index),
34
+ username: 'sub-' + index,
35
+ age: 20,
36
+ });
32
37
  if (index % 2 == 0) {
33
38
  const sub2_selfid = 'ss' + index;
34
- fd.push({ __table_id: sub2_selfid, __parent__table_id: sub_selfid, username: 'sub2-' + index, age: 20 });
39
+ fd.push({
40
+ __table_id: sub2_selfid,
41
+ __parent__table_id: sub_selfid,
42
+ username: 'sub2-' + index,
43
+ age: 20,
44
+ });
35
45
  }
36
46
  }
37
47
  }
@@ -39,37 +49,63 @@ function getData() {
39
49
  }
40
50
 
41
51
  export function ExampleGrid() {
42
- const renderContactsGrid = ({ data }) => {
43
- return (
44
- <div>
45
- <div>{'Test'}</div>
46
- </div>
47
- );
48
- };
49
52
  const [selected, setSelected] = React.useState(null);
50
- const [rows, set_rows] = React.useState<any[]>([]);
53
+
51
54
  const onSelectionChange = React.useCallback(({ selected }) => {
52
55
  setSelected(selected);
53
56
  }, []);
54
57
 
55
- React.useEffect(() => {
56
- setTimeout(() => {
57
- set_rows(getData());
58
- }, 1000);
58
+ const dataSource = React.useCallback(async (dt) => {
59
+ console.log('Start loading');
60
+ return await new Promise((resolve) => {
61
+ setTimeout(() => {
62
+ console.log('end loading');
63
+ resolve({ data: getData(), count: 999 });
64
+ }, 1000);
65
+ });
59
66
  }, []);
67
+
60
68
  return (
61
- <AzGrid
62
- dark
63
- allowChildRows
64
- onSelectionChange={onSelectionChange}
65
- selected={selected}
66
- contextMenuItems={contextMenuItems}
67
- customColumns={customColumns}
68
- columns={columns}
69
- rows={rows}
70
- leftColumns={leftColumns}
71
- gridOptions={{ rowIndexColumn: true, checkboxColumn: true }}
72
- />
69
+ <div>
70
+ <AzGrid
71
+ dark
72
+ allowChildRows
73
+ onSelectionChange={onSelectionChange}
74
+ selected={selected}
75
+ contextMenuItems={contextMenuItems}
76
+ customColumns={customColumns}
77
+ columns={columns}
78
+ leftColumns={leftColumns}
79
+ gridOptions={{
80
+ pagination: 'remote',
81
+ defaultLimit: 100,
82
+ limit: 100,
83
+ pageSizes: [100],
84
+ rowIndexColumn: true,
85
+ checkboxColumn: true,
86
+ }}
87
+ dataSource={dataSource}
88
+ />
89
+ <AzGrid
90
+ dark
91
+ allowChildRows
92
+ onSelectionChange={onSelectionChange}
93
+ selected={selected}
94
+ contextMenuItems={contextMenuItems}
95
+ customColumns={customColumns}
96
+ columns={columns}
97
+ leftColumns={leftColumns}
98
+ gridOptions={{
99
+ pagination: 'remote',
100
+ defaultLimit: 100,
101
+ limit: 100,
102
+ pageSizes: [100],
103
+ rowIndexColumn: true,
104
+ checkboxColumn: true,
105
+ }}
106
+ dataSource={dataSource}
107
+ />
108
+ </div>
73
109
  );
74
110
  }
75
111
  export default ExampleGrid;
package/src/index.tsx CHANGED
@@ -7,12 +7,5 @@ import React from 'react';
7
7
  import ReactDOM from 'react-dom/client';
8
8
  export default AzGrid;
9
9
 
10
- if (process.env!.NODE_ENV === 'production') {
11
- // set production urls
12
- // enable sentry
13
- } else if (process.env!.NODE_ENV === 'development') {
14
- const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
15
- root.render(<ExampleGrid />);
16
- } else {
17
- // set defaults
18
- }
10
+ // const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
11
+ // root.render(<ExampleGrid />);
@@ -55,7 +55,7 @@ type GridOptions = Partial<TypeDataGridProps>;
55
55
  /* -------------------------------------------------------------------------- */
56
56
  export type AzGridProps = {
57
57
  columns?: columnOrString[];
58
- rows?: any[] | ((args: any) => any[] | Promise<any[]>);
58
+ dataSource?: any[] | ((args: any) => any[] | Promise<any[] | any>);
59
59
 
60
60
  licenseKey?: string;
61
61
 
@@ -134,15 +134,25 @@ export function AzGrid(props: AzGridProps) {
134
134
  /* -------------------------------------------------------------------------- */
135
135
  const dataSource = React.useCallback(
136
136
  async (dt) => {
137
- let result_rows =
138
- typeof props.rows === 'function' ? await props.rows(dt) : props.rows;
139
-
140
- if (result_rows == null) return [];
137
+ let result_rows: any[] = [];
138
+ let result_data: any = undefined;
139
+ if (typeof props.dataSource === 'function') {
140
+ result_data = await props.dataSource(dt);
141
+ if (typeof result_data === 'object') {
142
+ result_rows = result_data.data;
143
+ } else result_rows = result_data;
144
+ } else {
145
+ result_rows = props.dataSource || [];
146
+ }
141
147
  if (!Array.isArray(result_rows)) result_rows = [result_rows];
142
148
  if (props.allowChildRows) result_rows = fix_parent_child_relations(result_rows);
149
+
150
+ if (result_data && typeof result_data === 'object') {
151
+ return { ...result_data, data: result_rows };
152
+ }
143
153
  return result_rows;
144
154
  },
145
- [props.rows]
155
+ [props.dataSource]
146
156
  );
147
157
  return (
148
158
  <DataGrid