@azrico/reactgrid 1.0.8 → 1.0.10
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/src/views/DataGrid.js +15 -7
- package/package.json +1 -1
- package/src/views/DataGrid.tsx +16 -8
|
@@ -46,13 +46,14 @@ function AzGrid(props) {
|
|
|
46
46
|
if (!Array.isArray(mcols)) return [];
|
|
47
47
|
/* ------------------------------- fix columns ------------------------------ */
|
|
48
48
|
mcols.map(r => {
|
|
49
|
+
if (r == null) return null;
|
|
49
50
|
if (typeof r === 'string') return {
|
|
50
51
|
field: r,
|
|
51
52
|
header: r
|
|
52
53
|
};
|
|
53
54
|
if (typeof r === 'object') {
|
|
54
55
|
let final_cl = {
|
|
55
|
-
name: r
|
|
56
|
+
name: get_col_name(r),
|
|
56
57
|
header: r.header || r.title || r.name || '-',
|
|
57
58
|
width: r.width || undefined
|
|
58
59
|
};
|
|
@@ -73,7 +74,7 @@ function AzGrid(props) {
|
|
|
73
74
|
/* ---------------------------- apply extensions ---------------------------- */
|
|
74
75
|
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
75
76
|
const ext = mcolExts[index];
|
|
76
|
-
const ext_cl = ext
|
|
77
|
+
const ext_cl = get_col_name(ext);
|
|
77
78
|
const mcol = final_columns.find(s => s.name === ext_cl);
|
|
78
79
|
if (!mcol) continue;
|
|
79
80
|
// if (ext.width) mcol.width = ext.width;
|
|
@@ -82,7 +83,7 @@ function AzGrid(props) {
|
|
|
82
83
|
/* ------------------------------- frozen cols ------------------------------ */
|
|
83
84
|
if (Array.isArray(leftColumns)) {
|
|
84
85
|
for (let index = 0; index < leftColumns.length; index++) {
|
|
85
|
-
const r = leftColumns[index];
|
|
86
|
+
const r = get_col_name(leftColumns[index]);
|
|
86
87
|
const mcol = final_columns.find(s => s.name === r);
|
|
87
88
|
if (mcol) {
|
|
88
89
|
mcol.locked = 'start';
|
|
@@ -91,7 +92,7 @@ function AzGrid(props) {
|
|
|
91
92
|
}
|
|
92
93
|
if (Array.isArray(rightColumns)) {
|
|
93
94
|
for (let index = 0; index < rightColumns.length; index++) {
|
|
94
|
-
const r = rightColumns[index];
|
|
95
|
+
const r = get_col_name(rightColumns[index]);
|
|
95
96
|
const mcol = final_columns.find(s => s.name === r);
|
|
96
97
|
if (mcol) {
|
|
97
98
|
mcol.locked = 'end';
|
|
@@ -101,7 +102,7 @@ function AzGrid(props) {
|
|
|
101
102
|
/* -------------------------------- ediatable ------------------------------- */
|
|
102
103
|
if (Array.isArray(editableColumns)) {
|
|
103
104
|
for (let index = 0; index < editableColumns.length; index++) {
|
|
104
|
-
const r = editableColumns[index];
|
|
105
|
+
const r = get_col_name(editableColumns[index]);
|
|
105
106
|
const mcol = final_columns.find(s => s.name === r);
|
|
106
107
|
if (mcol) {
|
|
107
108
|
// mcol.editor = editorWrapper;
|
|
@@ -114,7 +115,8 @@ function AzGrid(props) {
|
|
|
114
115
|
if (Array.isArray(customColumns)) {
|
|
115
116
|
for (let index = 0; index < customColumns.length; index++) {
|
|
116
117
|
const r = customColumns[index];
|
|
117
|
-
const
|
|
118
|
+
const rn = get_col_name(r);
|
|
119
|
+
const mcol = final_columns.find(s => s.name === rn);
|
|
118
120
|
if (mcol) {
|
|
119
121
|
//@ts-ignore
|
|
120
122
|
mcol.render = r.render;
|
|
@@ -135,6 +137,7 @@ function AzGrid(props) {
|
|
|
135
137
|
} else new_rows = props.rows || [];
|
|
136
138
|
/* -------------------------------------------------------------------------- */
|
|
137
139
|
if (!Array.isArray(new_rows)) new_rows = [];
|
|
140
|
+
new_rows = new_rows.filter(s => s != null);
|
|
138
141
|
/* -------------------------- fix child parent rel -------------------------- */
|
|
139
142
|
if (props.allowChildRows) new_rows = (0, _helpers.fix_parent_child_relations)(new_rows);
|
|
140
143
|
set_cached_rows(new_rows);
|
|
@@ -171,7 +174,6 @@ function DataGrid(props) {
|
|
|
171
174
|
const gridRef = _react.default.useRef(null);
|
|
172
175
|
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
173
176
|
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
174
|
-
const gridID = _react.default.useMemo(() => 'table-' + Date.now().valueOf(), []);
|
|
175
177
|
/* -------------------------------------------------------------------------- */
|
|
176
178
|
/* Create the grid */
|
|
177
179
|
/* -------------------------------------------------------------------------- */
|
|
@@ -250,6 +252,12 @@ function DataGrid(props) {
|
|
|
250
252
|
}));
|
|
251
253
|
}
|
|
252
254
|
/* -------------------------------------------------------------------------- */
|
|
255
|
+
function get_col_name(obj) {
|
|
256
|
+
if (!obj) return 'default';
|
|
257
|
+
if (typeof obj == 'string') return obj;
|
|
258
|
+
if (typeof obj != 'object') return 'default';
|
|
259
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
260
|
+
}
|
|
253
261
|
function get_default_key() {
|
|
254
262
|
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
255
263
|
}
|
package/package.json
CHANGED
package/src/views/DataGrid.tsx
CHANGED
|
@@ -121,10 +121,11 @@ export function AzGrid(props: AzGridProps) {
|
|
|
121
121
|
|
|
122
122
|
mcols
|
|
123
123
|
.map((r) => {
|
|
124
|
+
if (r == null) return null;
|
|
124
125
|
if (typeof r === 'string') return { field: r, header: r };
|
|
125
126
|
if (typeof r === 'object') {
|
|
126
127
|
let final_cl: MakeWriteable<ColumnDefinition> = {
|
|
127
|
-
name: r
|
|
128
|
+
name: get_col_name(r),
|
|
128
129
|
header: r.header || r.title || r.name || '-',
|
|
129
130
|
width: r.width || undefined,
|
|
130
131
|
};
|
|
@@ -148,7 +149,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
148
149
|
if (mcolExts && Array.isArray(mcolExts))
|
|
149
150
|
for (let index = 0; index < mcolExts.length; index++) {
|
|
150
151
|
const ext = mcolExts[index];
|
|
151
|
-
const ext_cl = ext
|
|
152
|
+
const ext_cl = get_col_name(ext);
|
|
152
153
|
const mcol = final_columns.find((s) => s.name === ext_cl);
|
|
153
154
|
if (!mcol) continue;
|
|
154
155
|
// if (ext.width) mcol.width = ext.width;
|
|
@@ -158,7 +159,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
158
159
|
/* ------------------------------- frozen cols ------------------------------ */
|
|
159
160
|
if (Array.isArray(leftColumns)) {
|
|
160
161
|
for (let index = 0; index < leftColumns.length; index++) {
|
|
161
|
-
const r = leftColumns[index];
|
|
162
|
+
const r = get_col_name(leftColumns[index]);
|
|
162
163
|
const mcol = final_columns.find((s) => s.name === r);
|
|
163
164
|
if (mcol) {
|
|
164
165
|
mcol.locked = 'start';
|
|
@@ -167,7 +168,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
167
168
|
}
|
|
168
169
|
if (Array.isArray(rightColumns)) {
|
|
169
170
|
for (let index = 0; index < rightColumns.length; index++) {
|
|
170
|
-
const r = rightColumns[index];
|
|
171
|
+
const r = get_col_name(rightColumns[index]);
|
|
171
172
|
const mcol = final_columns.find((s) => s.name === r);
|
|
172
173
|
if (mcol) {
|
|
173
174
|
mcol.locked = 'end';
|
|
@@ -177,7 +178,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
177
178
|
/* -------------------------------- ediatable ------------------------------- */
|
|
178
179
|
if (Array.isArray(editableColumns)) {
|
|
179
180
|
for (let index = 0; index < editableColumns.length; index++) {
|
|
180
|
-
const r = editableColumns[index];
|
|
181
|
+
const r = get_col_name(editableColumns[index]);
|
|
181
182
|
const mcol = final_columns.find((s) => s.name === r);
|
|
182
183
|
if (mcol) {
|
|
183
184
|
// mcol.editor = editorWrapper;
|
|
@@ -190,7 +191,8 @@ export function AzGrid(props: AzGridProps) {
|
|
|
190
191
|
if (Array.isArray(customColumns)) {
|
|
191
192
|
for (let index = 0; index < customColumns.length; index++) {
|
|
192
193
|
const r = customColumns[index];
|
|
193
|
-
const
|
|
194
|
+
const rn = get_col_name(r);
|
|
195
|
+
const mcol = final_columns.find((s) => s.name === rn);
|
|
194
196
|
if (mcol) {
|
|
195
197
|
//@ts-ignore
|
|
196
198
|
mcol.render = r.render;
|
|
@@ -213,6 +215,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
213
215
|
} else new_rows = props.rows || [];
|
|
214
216
|
/* -------------------------------------------------------------------------- */
|
|
215
217
|
if (!Array.isArray(new_rows)) new_rows = [];
|
|
218
|
+
new_rows = new_rows.filter((s) => s != null);
|
|
216
219
|
/* -------------------------- fix child parent rel -------------------------- */
|
|
217
220
|
if (props.allowChildRows) new_rows = fix_parent_child_relations(new_rows);
|
|
218
221
|
|
|
@@ -243,8 +246,6 @@ function DataGrid(props: DataGridProps) {
|
|
|
243
246
|
const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
|
|
244
247
|
const [menuRow, set_menuRow] = React.useState<any>(null);
|
|
245
248
|
|
|
246
|
-
const gridID = React.useMemo(() => 'table-' + Date.now().valueOf(), []);
|
|
247
|
-
|
|
248
249
|
/* -------------------------------------------------------------------------- */
|
|
249
250
|
/* Create the grid */
|
|
250
251
|
/* -------------------------------------------------------------------------- */
|
|
@@ -317,6 +318,13 @@ function DataGrid(props: DataGridProps) {
|
|
|
317
318
|
);
|
|
318
319
|
}
|
|
319
320
|
/* -------------------------------------------------------------------------- */
|
|
321
|
+
|
|
322
|
+
function get_col_name(obj: any): string {
|
|
323
|
+
if (!obj) return 'default';
|
|
324
|
+
if (typeof obj == 'string') return obj;
|
|
325
|
+
if (typeof obj != 'object') return 'default';
|
|
326
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
327
|
+
}
|
|
320
328
|
function get_default_key() {
|
|
321
329
|
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
322
330
|
}
|