@insticc/react-datagrid-2 1.1.9 → 1.1.11
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 +1 -1
- package/build/index.js +0 -7
- package/build/wrapper/ActionButton.js +0 -205
- package/build/wrapper/ColumnFilter.js +0 -105
- package/build/wrapper/ExportActions.js +0 -374
- package/build/wrapper/index.js +0 -675
- package/build/wrapper/styles/styles.css +0 -15
- package/build/wrapper/utils/GridHelper.js +0 -30
- package/build/wrapper/utils/filters.js +0 -63
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _material = require("@mui/material");
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _semanticUiReact = require("semantic-ui-react");
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var XLSX = _interopRequireWildcard(require("xlsx"));
|
|
12
|
-
var _jspdf = require("jspdf");
|
|
13
|
-
var _jspdfAutotable = _interopRequireDefault(require("jspdf-autotable"));
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
-
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 && {}.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; }
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
17
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
18
|
-
var ExportActions = function ExportActions(props) {
|
|
19
|
-
/**
|
|
20
|
-
* Exports the data grid data to an excel file.
|
|
21
|
-
* @returns Error if the data is invalid or empty.
|
|
22
|
-
*/
|
|
23
|
-
var handleExcelExportData = function handleExcelExportData() {
|
|
24
|
-
var data = props.data;
|
|
25
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
26
|
-
console.log('Invalid data format or empty data array');
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
var fieldNames = Object.keys(data[0]);
|
|
30
|
-
var dataArray = [fieldNames];
|
|
31
|
-
data.forEach(function (item) {
|
|
32
|
-
var rowData = [];
|
|
33
|
-
fieldNames.forEach(function (fieldName) {
|
|
34
|
-
var value = item[fieldName];
|
|
35
|
-
if (_typeof(value) === 'object' && value !== null) {
|
|
36
|
-
rowData.push(JSON.stringify(value));
|
|
37
|
-
} else {
|
|
38
|
-
rowData.push(value);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
dataArray.push(rowData);
|
|
42
|
-
});
|
|
43
|
-
var worksheet = XLSX.utils.aoa_to_sheet(dataArray);
|
|
44
|
-
var workbook = XLSX.utils.book_new();
|
|
45
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, 'All Data');
|
|
46
|
-
XLSX.writeFile(workbook, 'all_data.xlsx');
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Exports the rows based on the type provided to an excel file.
|
|
51
|
-
* @param {Object|Array} rows - the rows to export.
|
|
52
|
-
* @param {string} type - the type of export to be performed.
|
|
53
|
-
*/
|
|
54
|
-
var handleExcelExportRows = function handleExcelExportRows(rows, type) {
|
|
55
|
-
var rowData = rows.map(function (row) {
|
|
56
|
-
return row._valuesCache;
|
|
57
|
-
});
|
|
58
|
-
var fileName = getFileNameByType(type);
|
|
59
|
-
var worksheet = XLSX.utils.json_to_sheet(rowData);
|
|
60
|
-
var workbook = XLSX.utils.book_new();
|
|
61
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, 'Rows Data');
|
|
62
|
-
XLSX.writeFile(workbook, "".concat(fileName, ".xlsx"));
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Exports the data grid data to a pdf file.
|
|
67
|
-
* @returns Error if the data is invalid or empty.
|
|
68
|
-
*/
|
|
69
|
-
var handlePdfExportData = function handlePdfExportData() {
|
|
70
|
-
var data = props.data;
|
|
71
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
72
|
-
console.log('Invalid data format or empty data array');
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
var doc = new _jspdf.jsPDF();
|
|
76
|
-
var fileName = getFileNameByType('all');
|
|
77
|
-
var tableData = data.map(function (item) {
|
|
78
|
-
return Object.values(item);
|
|
79
|
-
});
|
|
80
|
-
var tableHeaders = Object.keys(data[0]);
|
|
81
|
-
(0, _jspdfAutotable["default"])(doc, {
|
|
82
|
-
head: [tableHeaders],
|
|
83
|
-
body: tableData
|
|
84
|
-
});
|
|
85
|
-
doc.save("".concat(fileName, ".pdf"));
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Exports the rows based on the type provided to a pdf file.
|
|
90
|
-
* @param {Object|Array} rows - the rows to export.
|
|
91
|
-
* @param {string} type - the type of export to be performed.
|
|
92
|
-
*/
|
|
93
|
-
// const handlePdfExportRows = (rows, type) => {
|
|
94
|
-
// const doc = new jsPDF();
|
|
95
|
-
// const fileName = getFileNameByType(type);
|
|
96
|
-
// const tableData = rows.map((row) => Object.values(row.original));
|
|
97
|
-
// const tableHeaders = props.columns.map((c) => c.header);
|
|
98
|
-
|
|
99
|
-
// autoTable(doc, {
|
|
100
|
-
// head: [tableHeaders],
|
|
101
|
-
// body: tableData,
|
|
102
|
-
// });
|
|
103
|
-
|
|
104
|
-
// doc.save(`${fileName}.pdf`);
|
|
105
|
-
// }
|
|
106
|
-
var handlePdfExportRows = function handlePdfExportRows(rows, type) {
|
|
107
|
-
var doc = new _jspdf.jsPDF();
|
|
108
|
-
var fileName = getFileNameByType(type);
|
|
109
|
-
var tableData = rows.map(function (row) {
|
|
110
|
-
return Object.values(row.original);
|
|
111
|
-
});
|
|
112
|
-
var columns = props.table.getAllFlatColumns();
|
|
113
|
-
var columnsToExport = [];
|
|
114
|
-
columns.forEach(function (col) {
|
|
115
|
-
if (col.id !== 'mrt-row-expand' || col.id !== 'mrt-row-expand') {
|
|
116
|
-
columnsToExport.push(col.id);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
// Get the column headers and data for the selected columns
|
|
120
|
-
// Iterate through the rows and format the data for the PDF
|
|
121
|
-
var pageWidth = doc.internal.pageSize.width; // Get page width
|
|
122
|
-
var pageHeight = doc.internal.pageSize.height; // Get page height
|
|
123
|
-
var margin = 5; // Set margin
|
|
124
|
-
var maxWidth = pageWidth - 2 * margin; // Calculate usable width
|
|
125
|
-
var fontSize = 8; // Set desired font size
|
|
126
|
-
var lineHeight = fontSize / 2; // Adjust line height based on font size
|
|
127
|
-
|
|
128
|
-
doc.setFontSize(fontSize); // Apply the font size globally
|
|
129
|
-
|
|
130
|
-
rows.forEach(function (row, rowIndex) {
|
|
131
|
-
if (rowIndex > 0) {
|
|
132
|
-
doc.addPage(); // Add a new page for every record except the first
|
|
133
|
-
}
|
|
134
|
-
var yPosition = margin; // Reset yPosition for each new page
|
|
135
|
-
|
|
136
|
-
columnsToExport.forEach(function (columnId) {
|
|
137
|
-
var value = row.original[columnId]; // Get the value of the column
|
|
138
|
-
|
|
139
|
-
if (columnId === "body") {
|
|
140
|
-
// Handle wrapping for 'body' column (longer text)
|
|
141
|
-
var wrappedText = doc.splitTextToSize(value, maxWidth); // Wrap text to fit
|
|
142
|
-
|
|
143
|
-
doc.text("".concat(columnId, ":"), margin, yPosition); // Print column label
|
|
144
|
-
yPosition += lineHeight; // Small gap after the label
|
|
145
|
-
doc.text(wrappedText, margin, yPosition); // Print wrapped text
|
|
146
|
-
yPosition += wrappedText.length * lineHeight; // Adjust Y position based on text length
|
|
147
|
-
doc.text("-------end of template-------", margin + 30, yPosition);
|
|
148
|
-
} else {
|
|
149
|
-
// Handle normal text for other columns
|
|
150
|
-
doc.text("".concat(columnId, ": ").concat(value), margin, yPosition);
|
|
151
|
-
yPosition += lineHeight; // Standard line spacing
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// Save the PDF
|
|
157
|
-
//doc.save("exported-columns.pdf");
|
|
158
|
-
|
|
159
|
-
doc.save("".concat(fileName, ".pdf"));
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Defines the export file name base on the export type.
|
|
164
|
-
* @param {string} type - the export type.
|
|
165
|
-
* @returns the export file name.
|
|
166
|
-
*/
|
|
167
|
-
var getFileNameByType = function getFileNameByType(type) {
|
|
168
|
-
switch (type) {
|
|
169
|
-
case 'page':
|
|
170
|
-
return 'page_rows_data';
|
|
171
|
-
case 'all':
|
|
172
|
-
return 'all_rows_data';
|
|
173
|
-
case 'selected':
|
|
174
|
-
return 'selected_rows_data';
|
|
175
|
-
default:
|
|
176
|
-
return 'rows_data';
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Renders the chosen excel export.
|
|
182
|
-
* @returns the excel export button element.
|
|
183
|
-
*/
|
|
184
|
-
var getExcelExports = function getExcelExports() {
|
|
185
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, props.excelOption === 'all' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
186
|
-
title: "Export All Data to Excel",
|
|
187
|
-
arrow: true
|
|
188
|
-
}, /*#__PURE__*/_react["default"].createElement("span", {
|
|
189
|
-
style: {
|
|
190
|
-
height: '35px'
|
|
191
|
-
}
|
|
192
|
-
}, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
193
|
-
onClick: handleExcelExportData,
|
|
194
|
-
icon: /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Icon, {
|
|
195
|
-
name: "file excel"
|
|
196
|
-
}),
|
|
197
|
-
label: {
|
|
198
|
-
basic: true,
|
|
199
|
-
color: 'green',
|
|
200
|
-
content: "Export All Data",
|
|
201
|
-
style: 'height: 100%'
|
|
202
|
-
},
|
|
203
|
-
basic: true,
|
|
204
|
-
color: "green",
|
|
205
|
-
style: {
|
|
206
|
-
height: '40px'
|
|
207
|
-
}
|
|
208
|
-
}))), props.excelOption === 'allRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
209
|
-
title: "Export All Rows to Excel",
|
|
210
|
-
arrow: true
|
|
211
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
212
|
-
disabled: props.table.getPrePaginationRowModel().rows.length === 0,
|
|
213
|
-
onClick: function onClick() {
|
|
214
|
-
return handleExcelExportRows(props.table.getPrePaginationRowModel().rows, 'all');
|
|
215
|
-
},
|
|
216
|
-
icon: "file excel",
|
|
217
|
-
label: {
|
|
218
|
-
basic: true,
|
|
219
|
-
color: 'green',
|
|
220
|
-
content: "Export All Rows"
|
|
221
|
-
},
|
|
222
|
-
basic: true,
|
|
223
|
-
color: "green",
|
|
224
|
-
style: {
|
|
225
|
-
height: '40px'
|
|
226
|
-
}
|
|
227
|
-
}))), props.excelOption === 'pageRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
228
|
-
title: "Export Page Rows to Excel",
|
|
229
|
-
arrow: true
|
|
230
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
231
|
-
disabled: props.table.getRowModel().rows.length === 0,
|
|
232
|
-
onClick: function onClick() {
|
|
233
|
-
return handleExcelExportRows(props.table.getRowModel().rows, 'page');
|
|
234
|
-
},
|
|
235
|
-
icon: "file excel",
|
|
236
|
-
label: {
|
|
237
|
-
basic: true,
|
|
238
|
-
color: 'green',
|
|
239
|
-
content: "Export Page Rows"
|
|
240
|
-
},
|
|
241
|
-
basic: true,
|
|
242
|
-
color: "green",
|
|
243
|
-
style: {
|
|
244
|
-
height: '40px'
|
|
245
|
-
}
|
|
246
|
-
}))), props.excelOption === 'selectedRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
247
|
-
title: "Export Selected Rows to Excel",
|
|
248
|
-
arrow: true
|
|
249
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
250
|
-
disabled: !props.table.getIsSomeRowsSelected() && !props.table.getIsAllRowsSelected(),
|
|
251
|
-
onClick: function onClick() {
|
|
252
|
-
return handleExcelExportRows(props.table.getSelectedRowModel().rows, 'selected');
|
|
253
|
-
},
|
|
254
|
-
icon: "file excel",
|
|
255
|
-
label: {
|
|
256
|
-
basic: true,
|
|
257
|
-
color: 'green',
|
|
258
|
-
content: "Export Selected Rows"
|
|
259
|
-
},
|
|
260
|
-
basic: true,
|
|
261
|
-
color: "green",
|
|
262
|
-
style: {
|
|
263
|
-
height: '40px'
|
|
264
|
-
}
|
|
265
|
-
}))));
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Renders the chosen pdf export.
|
|
270
|
-
* @returns the excel pdf button element.
|
|
271
|
-
*/
|
|
272
|
-
var getPdfExports = function getPdfExports() {
|
|
273
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, props.pdfOption === 'all' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
274
|
-
title: "Export All Data to PDF",
|
|
275
|
-
arrow: true
|
|
276
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
277
|
-
onClick: handlePdfExportData,
|
|
278
|
-
icon: /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Icon, {
|
|
279
|
-
name: "file pdf"
|
|
280
|
-
}),
|
|
281
|
-
label: {
|
|
282
|
-
basic: true,
|
|
283
|
-
color: 'red',
|
|
284
|
-
content: "Export All Data"
|
|
285
|
-
},
|
|
286
|
-
basic: true,
|
|
287
|
-
color: "red",
|
|
288
|
-
style: {
|
|
289
|
-
height: '40px'
|
|
290
|
-
}
|
|
291
|
-
}))), props.pdfOption === 'allRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
292
|
-
title: "Export All Rows to PDF",
|
|
293
|
-
arrow: true
|
|
294
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
295
|
-
disabled: props.table.getPrePaginationRowModel().rows.length === 0,
|
|
296
|
-
onClick: function onClick() {
|
|
297
|
-
return handlePdfExportRows(props.table.getPrePaginationRowModel().rows, 'all');
|
|
298
|
-
},
|
|
299
|
-
icon: "file pdf",
|
|
300
|
-
label: {
|
|
301
|
-
basic: true,
|
|
302
|
-
color: 'red',
|
|
303
|
-
content: "Export All Rows"
|
|
304
|
-
},
|
|
305
|
-
basic: true,
|
|
306
|
-
color: "red",
|
|
307
|
-
style: {
|
|
308
|
-
height: '40px'
|
|
309
|
-
}
|
|
310
|
-
}))), props.pdfOption === 'pageRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
311
|
-
title: "Export Page Rows to PDF",
|
|
312
|
-
arrow: true
|
|
313
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button, {
|
|
314
|
-
disabled: props.table.getRowModel().rows.length === 0,
|
|
315
|
-
onClick: function onClick() {
|
|
316
|
-
return handlePdfExportRows(props.table.getRowModel().rows, 'page');
|
|
317
|
-
},
|
|
318
|
-
icon: "file pdf",
|
|
319
|
-
label: {
|
|
320
|
-
basic: true,
|
|
321
|
-
color: 'red',
|
|
322
|
-
content: "Export Page Rows"
|
|
323
|
-
},
|
|
324
|
-
basic: true,
|
|
325
|
-
color: "red",
|
|
326
|
-
style: {
|
|
327
|
-
height: '40px'
|
|
328
|
-
}
|
|
329
|
-
}))), props.pdfOption === 'selectedRows' && /*#__PURE__*/_react["default"].createElement(_material.Tooltip, {
|
|
330
|
-
title: "Export Selected Rows to PDF",
|
|
331
|
-
arrow: true
|
|
332
|
-
}, /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_semanticUiReact.Button
|
|
333
|
-
// disabled={!props.table.getIsSomeRowsSelected() && !props.table.getIsAllRowsSelected()}
|
|
334
|
-
, {
|
|
335
|
-
onClick: function onClick() {
|
|
336
|
-
return handlePdfExportRows(props.table.getSelectedRowModel().rows, 'selected');
|
|
337
|
-
},
|
|
338
|
-
icon: "file pdf",
|
|
339
|
-
label: {
|
|
340
|
-
basic: true,
|
|
341
|
-
color: 'red',
|
|
342
|
-
content: "Export Selected Rows"
|
|
343
|
-
},
|
|
344
|
-
basic: true,
|
|
345
|
-
color: "red",
|
|
346
|
-
style: {
|
|
347
|
-
height: '40px'
|
|
348
|
-
}
|
|
349
|
-
}))));
|
|
350
|
-
};
|
|
351
|
-
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
352
|
-
style: {
|
|
353
|
-
display: 'flex',
|
|
354
|
-
flexDirection: 'row',
|
|
355
|
-
gap: '.5em'
|
|
356
|
-
}
|
|
357
|
-
}, props.hasExcelExport && getExcelExports(), props.hasPdfExport && getPdfExports());
|
|
358
|
-
};
|
|
359
|
-
ExportActions.propTypes = {
|
|
360
|
-
hasExcelExport: _propTypes["default"].bool.isRequired,
|
|
361
|
-
// defines whether the excel export should be shown
|
|
362
|
-
hasPdfExport: _propTypes["default"].bool.isRequired,
|
|
363
|
-
// defines whether the pdf export should be shown
|
|
364
|
-
excelOption: _propTypes["default"].string.isRequired,
|
|
365
|
-
// defines the excel export option
|
|
366
|
-
pdfOption: _propTypes["default"].string.isRequired,
|
|
367
|
-
// defines the pdf export option
|
|
368
|
-
table: _propTypes["default"].object.isRequired,
|
|
369
|
-
// the data grid table
|
|
370
|
-
data: _propTypes["default"].array.isRequired,
|
|
371
|
-
// the data grid data
|
|
372
|
-
columns: _propTypes["default"].array.isRequired // the data grid columns
|
|
373
|
-
};
|
|
374
|
-
var _default = exports["default"] = ExportActions;
|