@azrico/reactgrid 1.0.8 → 1.0.9
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 +13 -7
- package/package.json +1 -1
- package/src/views/DataGrid.tsx +14 -8
|
@@ -52,7 +52,7 @@ function AzGrid(props) {
|
|
|
52
52
|
};
|
|
53
53
|
if (typeof r === 'object') {
|
|
54
54
|
let final_cl = {
|
|
55
|
-
name: r
|
|
55
|
+
name: get_col_name(r),
|
|
56
56
|
header: r.header || r.title || r.name || '-',
|
|
57
57
|
width: r.width || undefined
|
|
58
58
|
};
|
|
@@ -73,7 +73,7 @@ function AzGrid(props) {
|
|
|
73
73
|
/* ---------------------------- apply extensions ---------------------------- */
|
|
74
74
|
if (mcolExts && Array.isArray(mcolExts)) for (let index = 0; index < mcolExts.length; index++) {
|
|
75
75
|
const ext = mcolExts[index];
|
|
76
|
-
const ext_cl = ext
|
|
76
|
+
const ext_cl = get_col_name(ext);
|
|
77
77
|
const mcol = final_columns.find(s => s.name === ext_cl);
|
|
78
78
|
if (!mcol) continue;
|
|
79
79
|
// if (ext.width) mcol.width = ext.width;
|
|
@@ -82,7 +82,7 @@ function AzGrid(props) {
|
|
|
82
82
|
/* ------------------------------- frozen cols ------------------------------ */
|
|
83
83
|
if (Array.isArray(leftColumns)) {
|
|
84
84
|
for (let index = 0; index < leftColumns.length; index++) {
|
|
85
|
-
const r = leftColumns[index];
|
|
85
|
+
const r = get_col_name(leftColumns[index]);
|
|
86
86
|
const mcol = final_columns.find(s => s.name === r);
|
|
87
87
|
if (mcol) {
|
|
88
88
|
mcol.locked = 'start';
|
|
@@ -91,7 +91,7 @@ function AzGrid(props) {
|
|
|
91
91
|
}
|
|
92
92
|
if (Array.isArray(rightColumns)) {
|
|
93
93
|
for (let index = 0; index < rightColumns.length; index++) {
|
|
94
|
-
const r = rightColumns[index];
|
|
94
|
+
const r = get_col_name(rightColumns[index]);
|
|
95
95
|
const mcol = final_columns.find(s => s.name === r);
|
|
96
96
|
if (mcol) {
|
|
97
97
|
mcol.locked = 'end';
|
|
@@ -101,7 +101,7 @@ function AzGrid(props) {
|
|
|
101
101
|
/* -------------------------------- ediatable ------------------------------- */
|
|
102
102
|
if (Array.isArray(editableColumns)) {
|
|
103
103
|
for (let index = 0; index < editableColumns.length; index++) {
|
|
104
|
-
const r = editableColumns[index];
|
|
104
|
+
const r = get_col_name(editableColumns[index]);
|
|
105
105
|
const mcol = final_columns.find(s => s.name === r);
|
|
106
106
|
if (mcol) {
|
|
107
107
|
// mcol.editor = editorWrapper;
|
|
@@ -114,7 +114,8 @@ function AzGrid(props) {
|
|
|
114
114
|
if (Array.isArray(customColumns)) {
|
|
115
115
|
for (let index = 0; index < customColumns.length; index++) {
|
|
116
116
|
const r = customColumns[index];
|
|
117
|
-
const
|
|
117
|
+
const rn = get_col_name(r);
|
|
118
|
+
const mcol = final_columns.find(s => s.name === rn);
|
|
118
119
|
if (mcol) {
|
|
119
120
|
//@ts-ignore
|
|
120
121
|
mcol.render = r.render;
|
|
@@ -171,7 +172,6 @@ function DataGrid(props) {
|
|
|
171
172
|
const gridRef = _react.default.useRef(null);
|
|
172
173
|
const [menuAnchorEl, set_menuAnchorEl] = _react.default.useState(null);
|
|
173
174
|
const [menuRow, set_menuRow] = _react.default.useState(null);
|
|
174
|
-
const gridID = _react.default.useMemo(() => 'table-' + Date.now().valueOf(), []);
|
|
175
175
|
/* -------------------------------------------------------------------------- */
|
|
176
176
|
/* Create the grid */
|
|
177
177
|
/* -------------------------------------------------------------------------- */
|
|
@@ -250,6 +250,12 @@ function DataGrid(props) {
|
|
|
250
250
|
}));
|
|
251
251
|
}
|
|
252
252
|
/* -------------------------------------------------------------------------- */
|
|
253
|
+
function get_col_name(obj) {
|
|
254
|
+
if (!obj) return 'default';
|
|
255
|
+
if (typeof obj == 'string') return obj;
|
|
256
|
+
if (typeof obj != 'object') return 'default';
|
|
257
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
258
|
+
}
|
|
253
259
|
function get_default_key() {
|
|
254
260
|
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
255
261
|
}
|
package/package.json
CHANGED
package/src/views/DataGrid.tsx
CHANGED
|
@@ -124,7 +124,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
124
124
|
if (typeof r === 'string') return { field: r, header: r };
|
|
125
125
|
if (typeof r === 'object') {
|
|
126
126
|
let final_cl: MakeWriteable<ColumnDefinition> = {
|
|
127
|
-
name: r
|
|
127
|
+
name: get_col_name(r),
|
|
128
128
|
header: r.header || r.title || r.name || '-',
|
|
129
129
|
width: r.width || undefined,
|
|
130
130
|
};
|
|
@@ -148,7 +148,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
148
148
|
if (mcolExts && Array.isArray(mcolExts))
|
|
149
149
|
for (let index = 0; index < mcolExts.length; index++) {
|
|
150
150
|
const ext = mcolExts[index];
|
|
151
|
-
const ext_cl = ext
|
|
151
|
+
const ext_cl = get_col_name(ext);
|
|
152
152
|
const mcol = final_columns.find((s) => s.name === ext_cl);
|
|
153
153
|
if (!mcol) continue;
|
|
154
154
|
// if (ext.width) mcol.width = ext.width;
|
|
@@ -158,7 +158,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
158
158
|
/* ------------------------------- frozen cols ------------------------------ */
|
|
159
159
|
if (Array.isArray(leftColumns)) {
|
|
160
160
|
for (let index = 0; index < leftColumns.length; index++) {
|
|
161
|
-
const r = leftColumns[index];
|
|
161
|
+
const r = get_col_name(leftColumns[index]);
|
|
162
162
|
const mcol = final_columns.find((s) => s.name === r);
|
|
163
163
|
if (mcol) {
|
|
164
164
|
mcol.locked = 'start';
|
|
@@ -167,7 +167,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
167
167
|
}
|
|
168
168
|
if (Array.isArray(rightColumns)) {
|
|
169
169
|
for (let index = 0; index < rightColumns.length; index++) {
|
|
170
|
-
const r = rightColumns[index];
|
|
170
|
+
const r = get_col_name(rightColumns[index]);
|
|
171
171
|
const mcol = final_columns.find((s) => s.name === r);
|
|
172
172
|
if (mcol) {
|
|
173
173
|
mcol.locked = 'end';
|
|
@@ -177,7 +177,7 @@ export function AzGrid(props: AzGridProps) {
|
|
|
177
177
|
/* -------------------------------- ediatable ------------------------------- */
|
|
178
178
|
if (Array.isArray(editableColumns)) {
|
|
179
179
|
for (let index = 0; index < editableColumns.length; index++) {
|
|
180
|
-
const r = editableColumns[index];
|
|
180
|
+
const r = get_col_name(editableColumns[index]);
|
|
181
181
|
const mcol = final_columns.find((s) => s.name === r);
|
|
182
182
|
if (mcol) {
|
|
183
183
|
// mcol.editor = editorWrapper;
|
|
@@ -190,7 +190,8 @@ export function AzGrid(props: AzGridProps) {
|
|
|
190
190
|
if (Array.isArray(customColumns)) {
|
|
191
191
|
for (let index = 0; index < customColumns.length; index++) {
|
|
192
192
|
const r = customColumns[index];
|
|
193
|
-
const
|
|
193
|
+
const rn = get_col_name(r);
|
|
194
|
+
const mcol = final_columns.find((s) => s.name === rn);
|
|
194
195
|
if (mcol) {
|
|
195
196
|
//@ts-ignore
|
|
196
197
|
mcol.render = r.render;
|
|
@@ -243,8 +244,6 @@ function DataGrid(props: DataGridProps) {
|
|
|
243
244
|
const [menuAnchorEl, set_menuAnchorEl] = React.useState<any>(null);
|
|
244
245
|
const [menuRow, set_menuRow] = React.useState<any>(null);
|
|
245
246
|
|
|
246
|
-
const gridID = React.useMemo(() => 'table-' + Date.now().valueOf(), []);
|
|
247
|
-
|
|
248
247
|
/* -------------------------------------------------------------------------- */
|
|
249
248
|
/* Create the grid */
|
|
250
249
|
/* -------------------------------------------------------------------------- */
|
|
@@ -317,6 +316,13 @@ function DataGrid(props: DataGridProps) {
|
|
|
317
316
|
);
|
|
318
317
|
}
|
|
319
318
|
/* -------------------------------------------------------------------------- */
|
|
319
|
+
|
|
320
|
+
function get_col_name(obj: any): string {
|
|
321
|
+
if (!obj) return 'default';
|
|
322
|
+
if (typeof obj == 'string') return obj;
|
|
323
|
+
if (typeof obj != 'object') return 'default';
|
|
324
|
+
return obj.name || obj.field || obj.key || obj.columnName || 'default';
|
|
325
|
+
}
|
|
320
326
|
function get_default_key() {
|
|
321
327
|
return 'ExpiryDate=2999-01-01,Z=1040577552';
|
|
322
328
|
}
|