nillud-data-table 1.0.2 → 1.0.4
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/index.js +255 -11
- package/package.json +6 -7
- package/dist/ExportSection-ZYOK6KMB.js +0 -247
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// components/DataTable.tsx
|
2
|
-
import
|
2
|
+
import { useImperativeHandle, useEffect as useEffect2, useState, useCallback, useMemo as useMemo2, forwardRef } from "react";
|
3
3
|
|
4
4
|
// components/TableHeader.tsx
|
5
5
|
import React from "react";
|
@@ -393,9 +393,253 @@ function useDebouncedEffect(callback, deps, delay) {
|
|
393
393
|
}, [...deps, delay]);
|
394
394
|
}
|
395
395
|
|
396
|
+
// components/export/WordExport.tsx
|
397
|
+
import {
|
398
|
+
AlignmentType,
|
399
|
+
Document,
|
400
|
+
Packer,
|
401
|
+
PageOrientation,
|
402
|
+
Paragraph,
|
403
|
+
Table,
|
404
|
+
TableCell,
|
405
|
+
TableRow,
|
406
|
+
TextRun,
|
407
|
+
VerticalAlign,
|
408
|
+
WidthType
|
409
|
+
} from "docx";
|
410
|
+
import saveAs from "file-saver";
|
411
|
+
|
412
|
+
// utils/exportUtils/ExportHelpers.ts
|
413
|
+
function prepareExportRows(columns, data) {
|
414
|
+
return data.map(
|
415
|
+
(row) => columns.map((col) => {
|
416
|
+
const value = row[col.field];
|
417
|
+
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
418
|
+
})
|
419
|
+
);
|
420
|
+
}
|
421
|
+
function prepareExportHeaders(columns) {
|
422
|
+
return columns.map((col) => col.title);
|
423
|
+
}
|
424
|
+
|
425
|
+
// components/export/WordExport.tsx
|
426
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
427
|
+
var WordExport = ({
|
428
|
+
wordData,
|
429
|
+
columns,
|
430
|
+
title,
|
431
|
+
options = {
|
432
|
+
fontSize: 20,
|
433
|
+
boldHeaders: false,
|
434
|
+
autoLandscape: false,
|
435
|
+
maxColumnsBeforeLandscape: 5
|
436
|
+
}
|
437
|
+
// exportCustomColumns
|
438
|
+
}) => {
|
439
|
+
const createNewWord = async () => {
|
440
|
+
const {
|
441
|
+
fontSize = 0,
|
442
|
+
boldHeaders = true,
|
443
|
+
autoLandscape = true,
|
444
|
+
maxColumnsBeforeLandscape = 5
|
445
|
+
} = options;
|
446
|
+
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
447
|
+
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
448
|
+
children: [new Paragraph({
|
449
|
+
children: [new TextRun({
|
450
|
+
text: header,
|
451
|
+
size: fontSize,
|
452
|
+
bold: boldHeaders
|
453
|
+
})],
|
454
|
+
alignment: AlignmentType.CENTER
|
455
|
+
})],
|
456
|
+
verticalAlign: VerticalAlign.CENTER
|
457
|
+
}));
|
458
|
+
const tableHeaderRow = new TableRow({ children: headerCells });
|
459
|
+
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
460
|
+
const rowCells = cells.map(
|
461
|
+
(value) => new TableCell({
|
462
|
+
children: [new Paragraph({
|
463
|
+
children: [new TextRun({
|
464
|
+
text: value,
|
465
|
+
size: fontSize
|
466
|
+
})],
|
467
|
+
alignment: AlignmentType.CENTER
|
468
|
+
})],
|
469
|
+
verticalAlign: VerticalAlign.CENTER
|
470
|
+
})
|
471
|
+
);
|
472
|
+
return new TableRow({ children: rowCells });
|
473
|
+
});
|
474
|
+
const table = new Table({
|
475
|
+
rows: [tableHeaderRow, ...rows],
|
476
|
+
width: { size: 11e3, type: WidthType.DXA },
|
477
|
+
indent: { size: -1e3, type: WidthType.DXA }
|
478
|
+
});
|
479
|
+
const doc = new Document({
|
480
|
+
sections: [{
|
481
|
+
children: [table, new Paragraph({ text: "" })],
|
482
|
+
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
483
|
+
}]
|
484
|
+
});
|
485
|
+
Packer.toBlob(doc).then((blob) => {
|
486
|
+
saveAs(blob, `${title}.docx`);
|
487
|
+
});
|
488
|
+
};
|
489
|
+
return /* @__PURE__ */ jsx13("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
490
|
+
};
|
491
|
+
var WordExport_default = WordExport;
|
492
|
+
|
493
|
+
// utils/exportUtils/exportUtils.ts
|
494
|
+
var generateExcelColumns = (columns, exportCustomColumns) => {
|
495
|
+
let excelColumns = columns.map((column) => ({
|
496
|
+
header: column.title,
|
497
|
+
key: column.field,
|
498
|
+
width: 20
|
499
|
+
}));
|
500
|
+
if (exportCustomColumns) {
|
501
|
+
exportCustomColumns.forEach((custom) => {
|
502
|
+
excelColumns = excelColumns.map(
|
503
|
+
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
504
|
+
);
|
505
|
+
});
|
506
|
+
}
|
507
|
+
return excelColumns;
|
508
|
+
};
|
509
|
+
var applyHeaderStyles = (row, columnCount) => {
|
510
|
+
row.height = 40;
|
511
|
+
row.font = { size: 12, bold: true };
|
512
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
513
|
+
for (let i = 1; i <= columnCount; i++) {
|
514
|
+
const cell = row.getCell(i);
|
515
|
+
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
516
|
+
cell.border = {
|
517
|
+
top: { style: "thin" },
|
518
|
+
left: { style: "thin" },
|
519
|
+
bottom: { style: "thin" },
|
520
|
+
right: { style: "thin" }
|
521
|
+
};
|
522
|
+
}
|
523
|
+
};
|
524
|
+
var applyRowStyles = (row, columnCount) => {
|
525
|
+
row.height = 40;
|
526
|
+
row.font = { size: 12 };
|
527
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
528
|
+
for (let i = 1; i <= columnCount; i++) {
|
529
|
+
const cell = row.getCell(i);
|
530
|
+
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
531
|
+
cell.border = {
|
532
|
+
top: { style: "thin" },
|
533
|
+
left: { style: "thin" },
|
534
|
+
bottom: { style: "thin" },
|
535
|
+
right: { style: "thin" }
|
536
|
+
};
|
537
|
+
}
|
538
|
+
};
|
539
|
+
var generateExcelDataRows = (columns, data) => {
|
540
|
+
return data.map((element) => {
|
541
|
+
const rowData = {};
|
542
|
+
columns.forEach((col) => {
|
543
|
+
const value = element[col.field];
|
544
|
+
rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
|
545
|
+
});
|
546
|
+
return rowData;
|
547
|
+
});
|
548
|
+
};
|
549
|
+
var setColumnAutoWidths = (sheet) => {
|
550
|
+
var _a;
|
551
|
+
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
552
|
+
var _a2;
|
553
|
+
let maxLength = 10;
|
554
|
+
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
555
|
+
const cellValue = cell.value ? String(cell.value) : "";
|
556
|
+
maxLength = Math.max(maxLength, cellValue.length + 5);
|
557
|
+
});
|
558
|
+
column.width = maxLength;
|
559
|
+
});
|
560
|
+
};
|
561
|
+
|
562
|
+
// components/export/ExportExcel.tsx
|
563
|
+
import ExcelJS from "exceljs";
|
564
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
565
|
+
var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
|
566
|
+
const exportExcel = () => {
|
567
|
+
const workbook = new ExcelJS.Workbook();
|
568
|
+
const sheet = workbook.addWorksheet(title, {
|
569
|
+
pageSetup: {
|
570
|
+
fitToPage: true,
|
571
|
+
fitToHeight: 2,
|
572
|
+
fitToWidth: 1,
|
573
|
+
orientation: "landscape"
|
574
|
+
},
|
575
|
+
headerFooter: {
|
576
|
+
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
577
|
+
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
578
|
+
}
|
579
|
+
});
|
580
|
+
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
581
|
+
sheet.columns = excelColumns;
|
582
|
+
const headerRow = sheet.getRow(1);
|
583
|
+
applyHeaderStyles(headerRow, sheet.columns.length);
|
584
|
+
const dataRows = generateExcelDataRows(columns, excelData);
|
585
|
+
dataRows.forEach((data) => {
|
586
|
+
const row = sheet.addRow(data);
|
587
|
+
applyRowStyles(row, sheet.columns.length);
|
588
|
+
});
|
589
|
+
setColumnAutoWidths(sheet);
|
590
|
+
if (excelData.length > 15) {
|
591
|
+
sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
|
592
|
+
} else {
|
593
|
+
sheet.pageSetup.fitToHeight = 1;
|
594
|
+
}
|
595
|
+
workbook.xlsx.writeBuffer().then((data) => {
|
596
|
+
const blob = new Blob([data], {
|
597
|
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
598
|
+
});
|
599
|
+
const url = window.URL.createObjectURL(blob);
|
600
|
+
const anchor = document.createElement("a");
|
601
|
+
anchor.href = url;
|
602
|
+
anchor.download = `${title}.xlsx`;
|
603
|
+
anchor.click();
|
604
|
+
window.URL.revokeObjectURL(url);
|
605
|
+
});
|
606
|
+
};
|
607
|
+
return /* @__PURE__ */ jsx14("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
608
|
+
};
|
609
|
+
var ExportExcel_default = ExportExcel;
|
610
|
+
|
611
|
+
// components/ExportSection.tsx
|
612
|
+
import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs5 } from "react/jsx-runtime";
|
613
|
+
var ExportSection = ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableData, columns, tableName, exportCustomColumns, wordOptions }) => {
|
614
|
+
return /* @__PURE__ */ jsx15(Fragment2, { children: /* @__PURE__ */ jsxs5("div", { className: "ndt-download-section", children: [
|
615
|
+
/* @__PURE__ */ jsx15("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
|
616
|
+
/* @__PURE__ */ jsxs5("div", { className: "ndt-download-buttons", children: [
|
617
|
+
wordBtn && /* @__PURE__ */ jsx15(
|
618
|
+
WordExport_default,
|
619
|
+
{
|
620
|
+
wordData: tableData,
|
621
|
+
columns,
|
622
|
+
title: tableName,
|
623
|
+
exportCustomColumns,
|
624
|
+
options: wordOptions
|
625
|
+
}
|
626
|
+
),
|
627
|
+
excelBtn && /* @__PURE__ */ jsx15(
|
628
|
+
ExportExcel_default,
|
629
|
+
{
|
630
|
+
excelData: tableData,
|
631
|
+
columns,
|
632
|
+
title: tableName,
|
633
|
+
exportCustomColumns
|
634
|
+
}
|
635
|
+
)
|
636
|
+
] })
|
637
|
+
] }) });
|
638
|
+
};
|
639
|
+
var ExportSection_default = ExportSection;
|
640
|
+
|
396
641
|
// components/DataTable.tsx
|
397
|
-
import { jsx as
|
398
|
-
var ExportSection = React3.lazy(() => import("./ExportSection-ZYOK6KMB.js"));
|
642
|
+
import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
|
399
643
|
var DataTable = forwardRef(({
|
400
644
|
tableData,
|
401
645
|
columns,
|
@@ -489,9 +733,9 @@ var DataTable = forwardRef(({
|
|
489
733
|
getData: () => processedData,
|
490
734
|
getCurrentData: () => displayData
|
491
735
|
}), [processedData, displayData]);
|
492
|
-
return /* @__PURE__ */
|
493
|
-
|
494
|
-
|
736
|
+
return /* @__PURE__ */ jsxs6("div", { className: "ndt-table-container", children: [
|
737
|
+
(wordBtn || excelBtn) && /* @__PURE__ */ jsx16(
|
738
|
+
ExportSection_default,
|
495
739
|
{
|
496
740
|
wordBtn,
|
497
741
|
excelBtn,
|
@@ -502,9 +746,9 @@ var DataTable = forwardRef(({
|
|
502
746
|
exportCustomColumns,
|
503
747
|
wordOptions
|
504
748
|
}
|
505
|
-
)
|
506
|
-
/* @__PURE__ */
|
507
|
-
/* @__PURE__ */
|
749
|
+
),
|
750
|
+
/* @__PURE__ */ jsxs6("div", { className: "ndt-table", children: [
|
751
|
+
/* @__PURE__ */ jsx16(
|
508
752
|
TableHeader_default,
|
509
753
|
{
|
510
754
|
columns,
|
@@ -516,7 +760,7 @@ var DataTable = forwardRef(({
|
|
516
760
|
headerGroup
|
517
761
|
}
|
518
762
|
),
|
519
|
-
loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */
|
763
|
+
loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */ jsx16("span", { style: { marginLeft: 10, fontWeight: "bold" }, children: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445..." }) : /* @__PURE__ */ jsx16(
|
520
764
|
TableBody_default,
|
521
765
|
{
|
522
766
|
tableData: displayData,
|
@@ -530,7 +774,7 @@ var DataTable = forwardRef(({
|
|
530
774
|
isTitles
|
531
775
|
}
|
532
776
|
),
|
533
|
-
isFooter && /* @__PURE__ */
|
777
|
+
isFooter && /* @__PURE__ */ jsx16(
|
534
778
|
TableFooter_default,
|
535
779
|
{
|
536
780
|
paginationCounts,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nillud-data-table",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/index.cjs",
|
6
6
|
"module": "./dist/index.js",
|
@@ -23,15 +23,14 @@
|
|
23
23
|
"./styles.css": "./dist/styles.css"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
|
-
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
27
|
-
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
28
|
-
},
|
29
|
-
"dependencies": {
|
30
26
|
"docx": "^8.1.2",
|
31
27
|
"exceljs": "^4.3.0",
|
32
|
-
"file-saver": "^2.0.5"
|
28
|
+
"file-saver": "^2.0.5",
|
29
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
30
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
33
31
|
},
|
34
32
|
"devDependencies": {
|
33
|
+
"@types/file-saver": "^2.0.7",
|
35
34
|
"@types/react": "^19.1.3",
|
36
35
|
"@types/react-dom": "^19.1.3",
|
37
36
|
"sass": "^1.87.0",
|
@@ -42,4 +41,4 @@
|
|
42
41
|
"build": "tsup && npm run build:styles",
|
43
42
|
"build:styles": "node build-styles.js"
|
44
43
|
}
|
45
|
-
}
|
44
|
+
}
|
@@ -1,247 +0,0 @@
|
|
1
|
-
// components/export/WordExport.tsx
|
2
|
-
import {
|
3
|
-
AlignmentType,
|
4
|
-
Document,
|
5
|
-
Packer,
|
6
|
-
PageOrientation,
|
7
|
-
Paragraph,
|
8
|
-
Table,
|
9
|
-
TableCell,
|
10
|
-
TableRow,
|
11
|
-
TextRun,
|
12
|
-
VerticalAlign,
|
13
|
-
WidthType
|
14
|
-
} from "docx";
|
15
|
-
import saveAs from "file-saver";
|
16
|
-
|
17
|
-
// utils/exportUtils/ExportHelpers.ts
|
18
|
-
function prepareExportRows(columns, data) {
|
19
|
-
return data.map(
|
20
|
-
(row) => columns.map((col) => {
|
21
|
-
const value = row[col.field];
|
22
|
-
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
23
|
-
})
|
24
|
-
);
|
25
|
-
}
|
26
|
-
function prepareExportHeaders(columns) {
|
27
|
-
return columns.map((col) => col.title);
|
28
|
-
}
|
29
|
-
|
30
|
-
// components/export/WordExport.tsx
|
31
|
-
import { jsx } from "react/jsx-runtime";
|
32
|
-
var WordExport = ({
|
33
|
-
wordData,
|
34
|
-
columns,
|
35
|
-
title,
|
36
|
-
options = {
|
37
|
-
fontSize: 20,
|
38
|
-
boldHeaders: false,
|
39
|
-
autoLandscape: false,
|
40
|
-
maxColumnsBeforeLandscape: 5
|
41
|
-
}
|
42
|
-
// exportCustomColumns
|
43
|
-
}) => {
|
44
|
-
const createNewWord = async () => {
|
45
|
-
const {
|
46
|
-
fontSize = 0,
|
47
|
-
boldHeaders = true,
|
48
|
-
autoLandscape = true,
|
49
|
-
maxColumnsBeforeLandscape = 5
|
50
|
-
} = options;
|
51
|
-
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
52
|
-
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
53
|
-
children: [new Paragraph({
|
54
|
-
children: [new TextRun({
|
55
|
-
text: header,
|
56
|
-
size: fontSize,
|
57
|
-
bold: boldHeaders
|
58
|
-
})],
|
59
|
-
alignment: AlignmentType.CENTER
|
60
|
-
})],
|
61
|
-
verticalAlign: VerticalAlign.CENTER
|
62
|
-
}));
|
63
|
-
const tableHeaderRow = new TableRow({ children: headerCells });
|
64
|
-
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
65
|
-
const rowCells = cells.map(
|
66
|
-
(value) => new TableCell({
|
67
|
-
children: [new Paragraph({
|
68
|
-
children: [new TextRun({
|
69
|
-
text: value,
|
70
|
-
size: fontSize
|
71
|
-
})],
|
72
|
-
alignment: AlignmentType.CENTER
|
73
|
-
})],
|
74
|
-
verticalAlign: VerticalAlign.CENTER
|
75
|
-
})
|
76
|
-
);
|
77
|
-
return new TableRow({ children: rowCells });
|
78
|
-
});
|
79
|
-
const table = new Table({
|
80
|
-
rows: [tableHeaderRow, ...rows],
|
81
|
-
width: { size: 11e3, type: WidthType.DXA },
|
82
|
-
indent: { size: -1e3, type: WidthType.DXA }
|
83
|
-
});
|
84
|
-
const doc = new Document({
|
85
|
-
sections: [{
|
86
|
-
children: [table, new Paragraph({ text: "" })],
|
87
|
-
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
88
|
-
}]
|
89
|
-
});
|
90
|
-
Packer.toBlob(doc).then((blob) => {
|
91
|
-
saveAs(blob, `${title}.docx`);
|
92
|
-
});
|
93
|
-
};
|
94
|
-
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
95
|
-
};
|
96
|
-
var WordExport_default = WordExport;
|
97
|
-
|
98
|
-
// utils/exportUtils/exportUtils.ts
|
99
|
-
var generateExcelColumns = (columns, exportCustomColumns) => {
|
100
|
-
let excelColumns = columns.map((column) => ({
|
101
|
-
header: column.title,
|
102
|
-
key: column.field,
|
103
|
-
width: 20
|
104
|
-
}));
|
105
|
-
if (exportCustomColumns) {
|
106
|
-
exportCustomColumns.forEach((custom) => {
|
107
|
-
excelColumns = excelColumns.map(
|
108
|
-
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
109
|
-
);
|
110
|
-
});
|
111
|
-
}
|
112
|
-
return excelColumns;
|
113
|
-
};
|
114
|
-
var applyHeaderStyles = (row, columnCount) => {
|
115
|
-
row.height = 40;
|
116
|
-
row.font = { size: 12, bold: true };
|
117
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
118
|
-
for (let i = 1; i <= columnCount; i++) {
|
119
|
-
const cell = row.getCell(i);
|
120
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
121
|
-
cell.border = {
|
122
|
-
top: { style: "thin" },
|
123
|
-
left: { style: "thin" },
|
124
|
-
bottom: { style: "thin" },
|
125
|
-
right: { style: "thin" }
|
126
|
-
};
|
127
|
-
}
|
128
|
-
};
|
129
|
-
var applyRowStyles = (row, columnCount) => {
|
130
|
-
row.height = 40;
|
131
|
-
row.font = { size: 12 };
|
132
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
133
|
-
for (let i = 1; i <= columnCount; i++) {
|
134
|
-
const cell = row.getCell(i);
|
135
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
136
|
-
cell.border = {
|
137
|
-
top: { style: "thin" },
|
138
|
-
left: { style: "thin" },
|
139
|
-
bottom: { style: "thin" },
|
140
|
-
right: { style: "thin" }
|
141
|
-
};
|
142
|
-
}
|
143
|
-
};
|
144
|
-
var generateExcelDataRows = (columns, data) => {
|
145
|
-
return data.map((element) => {
|
146
|
-
const rowData = {};
|
147
|
-
columns.forEach((col) => {
|
148
|
-
const value = element[col.field];
|
149
|
-
rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
|
150
|
-
});
|
151
|
-
return rowData;
|
152
|
-
});
|
153
|
-
};
|
154
|
-
var setColumnAutoWidths = (sheet) => {
|
155
|
-
var _a;
|
156
|
-
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
157
|
-
var _a2;
|
158
|
-
let maxLength = 10;
|
159
|
-
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
160
|
-
const cellValue = cell.value ? String(cell.value) : "";
|
161
|
-
maxLength = Math.max(maxLength, cellValue.length + 5);
|
162
|
-
});
|
163
|
-
column.width = maxLength;
|
164
|
-
});
|
165
|
-
};
|
166
|
-
|
167
|
-
// components/export/ExportExcel.tsx
|
168
|
-
import ExcelJS from "exceljs";
|
169
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
170
|
-
var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
|
171
|
-
const exportExcel = () => {
|
172
|
-
const workbook = new ExcelJS.Workbook();
|
173
|
-
const sheet = workbook.addWorksheet(title, {
|
174
|
-
pageSetup: {
|
175
|
-
fitToPage: true,
|
176
|
-
fitToHeight: 2,
|
177
|
-
fitToWidth: 1,
|
178
|
-
orientation: "landscape"
|
179
|
-
},
|
180
|
-
headerFooter: {
|
181
|
-
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
182
|
-
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
183
|
-
}
|
184
|
-
});
|
185
|
-
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
186
|
-
sheet.columns = excelColumns;
|
187
|
-
const headerRow = sheet.getRow(1);
|
188
|
-
applyHeaderStyles(headerRow, sheet.columns.length);
|
189
|
-
const dataRows = generateExcelDataRows(columns, excelData);
|
190
|
-
dataRows.forEach((data) => {
|
191
|
-
const row = sheet.addRow(data);
|
192
|
-
applyRowStyles(row, sheet.columns.length);
|
193
|
-
});
|
194
|
-
setColumnAutoWidths(sheet);
|
195
|
-
if (excelData.length > 15) {
|
196
|
-
sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
|
197
|
-
} else {
|
198
|
-
sheet.pageSetup.fitToHeight = 1;
|
199
|
-
}
|
200
|
-
workbook.xlsx.writeBuffer().then((data) => {
|
201
|
-
const blob = new Blob([data], {
|
202
|
-
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
203
|
-
});
|
204
|
-
const url = window.URL.createObjectURL(blob);
|
205
|
-
const anchor = document.createElement("a");
|
206
|
-
anchor.href = url;
|
207
|
-
anchor.download = `${title}.xlsx`;
|
208
|
-
anchor.click();
|
209
|
-
window.URL.revokeObjectURL(url);
|
210
|
-
});
|
211
|
-
};
|
212
|
-
return /* @__PURE__ */ jsx2("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
213
|
-
};
|
214
|
-
var ExportExcel_default = ExportExcel;
|
215
|
-
|
216
|
-
// components/ExportSection.tsx
|
217
|
-
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
218
|
-
var ExportSection = ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableData, columns, tableName, exportCustomColumns, wordOptions }) => {
|
219
|
-
return /* @__PURE__ */ jsx3(Fragment, { children: /* @__PURE__ */ jsxs("div", { className: "ndt-download-section", children: [
|
220
|
-
/* @__PURE__ */ jsx3("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
|
221
|
-
/* @__PURE__ */ jsxs("div", { className: "ndt-download-buttons", children: [
|
222
|
-
wordBtn && /* @__PURE__ */ jsx3(
|
223
|
-
WordExport_default,
|
224
|
-
{
|
225
|
-
wordData: tableData,
|
226
|
-
columns,
|
227
|
-
title: tableName,
|
228
|
-
exportCustomColumns,
|
229
|
-
options: wordOptions
|
230
|
-
}
|
231
|
-
),
|
232
|
-
excelBtn && /* @__PURE__ */ jsx3(
|
233
|
-
ExportExcel_default,
|
234
|
-
{
|
235
|
-
excelData: tableData,
|
236
|
-
columns,
|
237
|
-
title: tableName,
|
238
|
-
exportCustomColumns
|
239
|
-
}
|
240
|
-
)
|
241
|
-
] })
|
242
|
-
] }) });
|
243
|
-
};
|
244
|
-
var ExportSection_default = ExportSection;
|
245
|
-
export {
|
246
|
-
ExportSection_default as default
|
247
|
-
};
|