nillud-data-table 1.0.7 → 1.1.0
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/README.md +24 -22
- package/dist/DataTable.types-H_KYwjEQ.d.ts +69 -0
- package/dist/export/index.d.ts +17 -0
- package/dist/export/index.js +254 -0
- package/dist/index.d.ts +5 -86
- package/dist/index.js +11 -271
- package/package.json +8 -5
package/README.md
CHANGED
@@ -86,6 +86,7 @@ const data = [{ name: 'Иван' }]
|
|
86
86
|
| [paginationCounts](#paginationcounts) | - | array<number> | Принимает массив чисел, число - количество строк для пагинации, (0 это все) |
|
87
87
|
| [scrollable](#scrollable) | - | boolean | Зафиксировать высоту таблицы и добавить скролл |
|
88
88
|
| [scrollHeight](#scrollheight) | - | number | Высота тела таблицы, работает, если scrollable: true |
|
89
|
+
| [exportSectionComponent](#exportsectioncomponent) | - | import module| Необходимо импортировать модуль ExportSection
|
89
90
|
| [exportCustomColumns](#exportcustomcolumns) | - | array [\{\}] | Принимает в себя массив объектов (\{\ key: string, width: number \}\) |
|
90
91
|
| [excelBtn](#excelbtn) | - | boolean | Показывать кнопку экспорта Excel |
|
91
92
|
| [wordBtn](#wordbtn) | - | boolean | Показывать кнопку экспорта Word |
|
@@ -413,6 +414,29 @@ scrollable
|
|
413
414
|
scrollHeight={410}
|
414
415
|
```
|
415
416
|
|
417
|
+
### exportSectionComponent
|
418
|
+
|
419
|
+
Необязательный параметр. Необходимо подключить модуль ExportSection и установить пакеты для экспорта Word и Excel
|
420
|
+
|
421
|
+
```bash
|
422
|
+
npm i exceljs docx file-saver
|
423
|
+
-или-
|
424
|
+
yarn add exceljs docx file-saver
|
425
|
+
```
|
426
|
+
|
427
|
+
Использование:
|
428
|
+
|
429
|
+
```tsx
|
430
|
+
import { ExportSection } from 'nillud-data-table/export'
|
431
|
+
|
432
|
+
<DataTable
|
433
|
+
tableData={tableData}
|
434
|
+
columns={columns}
|
435
|
+
tableName={'current-tasks'}
|
436
|
+
ExportSectionComponent={ExportSection}
|
437
|
+
/>
|
438
|
+
```
|
439
|
+
|
416
440
|
### exportCustomColumns
|
417
441
|
|
418
442
|
Необязательный параметр. Принимает в себя массив объектов формата.
|
@@ -445,17 +469,6 @@ npm i exceljs
|
|
445
469
|
yarn add exceljs
|
446
470
|
```
|
447
471
|
|
448
|
-
```tsx
|
449
|
-
import ExportExcel from 'nillud-data-table/export/ExportExcel';
|
450
|
-
|
451
|
-
<DataTable>
|
452
|
-
...
|
453
|
-
excelBtn
|
454
|
-
ExportExcelComponent={ExportExcel}
|
455
|
-
...
|
456
|
-
</DataTable>
|
457
|
-
```
|
458
|
-
|
459
472
|
### wordBtn
|
460
473
|
|
461
474
|
Необязательный параметр. Тип **boolean**, по умолчанию **false**. При значении **true** над таблицей с правой стороны появляется кнопка экспорта Word, которая по умолчанию принимает в себя исходный массив **tableData**
|
@@ -468,17 +481,6 @@ npm i docx file-saver
|
|
468
481
|
yarn add docx file-saver
|
469
482
|
```
|
470
483
|
|
471
|
-
```tsx
|
472
|
-
import WordExport from 'nillud-data-table/export/WordExport';
|
473
|
-
|
474
|
-
<DataTable>
|
475
|
-
...
|
476
|
-
wordBtn
|
477
|
-
WordExportComponent={WordExport}
|
478
|
-
...
|
479
|
-
</DataTable>
|
480
|
-
```
|
481
|
-
|
482
484
|
### wordOptions
|
483
485
|
|
484
486
|
Необязательный параметр. Используется вместе с **wordBtn**. Принимает в себя объект
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { ReactElement } from 'react';
|
2
|
+
|
3
|
+
type TableElement = {
|
4
|
+
[key: string]: string | number;
|
5
|
+
};
|
6
|
+
type TableData = Array<TableElement>;
|
7
|
+
type Column = {
|
8
|
+
field: string;
|
9
|
+
title: string;
|
10
|
+
width?: number;
|
11
|
+
autoinc?: boolean;
|
12
|
+
formatter?: (cell: string, row: TableElement) => ReactElement;
|
13
|
+
exportCustomCell?: (cell: string, row: TableElement) => string;
|
14
|
+
headerFilter?: (headerValue: string, rowValue: string) => string;
|
15
|
+
sortable?: boolean;
|
16
|
+
filterable?: boolean;
|
17
|
+
};
|
18
|
+
type ExportOptions = {
|
19
|
+
fontSize?: number;
|
20
|
+
boldHeaders?: boolean;
|
21
|
+
autoLandscape?: boolean;
|
22
|
+
maxColumnsBeforeLandscape?: number;
|
23
|
+
};
|
24
|
+
type TableProps = {
|
25
|
+
tableData: TableData;
|
26
|
+
columns: Array<Column>;
|
27
|
+
tableName: string;
|
28
|
+
loading?: boolean;
|
29
|
+
loadingElement?: ReactElement | null;
|
30
|
+
isFooter?: boolean;
|
31
|
+
paginationCounts?: Array<number> | null;
|
32
|
+
scrollable?: boolean;
|
33
|
+
scrollHeight?: number;
|
34
|
+
exportCustomColumns?: Array<{
|
35
|
+
header: string;
|
36
|
+
key: string;
|
37
|
+
width: number;
|
38
|
+
}> | null;
|
39
|
+
excelBtn?: boolean;
|
40
|
+
wordBtn?: boolean;
|
41
|
+
downloadSectionLeftSideContent?: ReactElement | null;
|
42
|
+
headerGroup?: Array<{
|
43
|
+
title: string;
|
44
|
+
cols: number;
|
45
|
+
}> | null;
|
46
|
+
groupBy?: string | null;
|
47
|
+
isTitles?: boolean;
|
48
|
+
wordOptions?: ExportOptions;
|
49
|
+
ExportSectionComponent?: React.ComponentType<{
|
50
|
+
wordBtn: boolean;
|
51
|
+
excelBtn: boolean;
|
52
|
+
downloadSectionLeftSideContent: React.ReactNode;
|
53
|
+
tableData: TableData;
|
54
|
+
columns: Array<Column>;
|
55
|
+
tableName: string;
|
56
|
+
exportCustomColumns?: Array<{
|
57
|
+
header: string;
|
58
|
+
key: string;
|
59
|
+
width: number;
|
60
|
+
}> | null;
|
61
|
+
wordOptions?: any;
|
62
|
+
}>;
|
63
|
+
};
|
64
|
+
type DataTableRef = {
|
65
|
+
getData: () => TableData;
|
66
|
+
getCurrentData: () => TableData;
|
67
|
+
};
|
68
|
+
|
69
|
+
export type { Column as C, DataTableRef as D, ExportOptions as E, TableProps as T, TableElement as a, TableData as b };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
+
import { ReactElement } from 'react';
|
3
|
+
import { b as TableData, C as Column, T as TableProps, E as ExportOptions } from '../DataTable.types-H_KYwjEQ.js';
|
4
|
+
|
5
|
+
type Props = {
|
6
|
+
wordBtn: boolean;
|
7
|
+
excelBtn: boolean;
|
8
|
+
downloadSectionLeftSideContent: ReactElement | null;
|
9
|
+
tableData: TableData;
|
10
|
+
columns: Array<Column>;
|
11
|
+
tableName: string;
|
12
|
+
exportCustomColumns?: TableProps['exportCustomColumns'];
|
13
|
+
wordOptions?: ExportOptions;
|
14
|
+
};
|
15
|
+
declare const ExportSection: ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableData, columns, tableName, exportCustomColumns, wordOptions }: Props) => react_jsx_runtime.JSX.Element;
|
16
|
+
|
17
|
+
export { ExportSection };
|
@@ -0,0 +1,254 @@
|
|
1
|
+
// utils/exportUtils/ExportHelpers.ts
|
2
|
+
function prepareExportRows(columns, data) {
|
3
|
+
return data.map(
|
4
|
+
(row) => columns.map((col) => {
|
5
|
+
const value = row[col.field];
|
6
|
+
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
7
|
+
})
|
8
|
+
);
|
9
|
+
}
|
10
|
+
function prepareExportHeaders(columns) {
|
11
|
+
return columns.map((col) => col.title);
|
12
|
+
}
|
13
|
+
|
14
|
+
// components/export/WordExport.tsx
|
15
|
+
import {
|
16
|
+
AlignmentType,
|
17
|
+
Document,
|
18
|
+
Packer,
|
19
|
+
PageOrientation,
|
20
|
+
Paragraph,
|
21
|
+
Table,
|
22
|
+
TableCell,
|
23
|
+
TableRow,
|
24
|
+
TextRun,
|
25
|
+
VerticalAlign,
|
26
|
+
WidthType
|
27
|
+
} from "docx";
|
28
|
+
import { saveAs } from "file-saver";
|
29
|
+
import { jsx } from "react/jsx-runtime";
|
30
|
+
var WordExport = ({
|
31
|
+
wordData,
|
32
|
+
columns,
|
33
|
+
title,
|
34
|
+
options = {
|
35
|
+
fontSize: 20,
|
36
|
+
boldHeaders: false,
|
37
|
+
autoLandscape: false,
|
38
|
+
maxColumnsBeforeLandscape: 5
|
39
|
+
}
|
40
|
+
// exportCustomColumns
|
41
|
+
}) => {
|
42
|
+
const createNewWord = async () => {
|
43
|
+
const {
|
44
|
+
fontSize = 0,
|
45
|
+
boldHeaders = true,
|
46
|
+
autoLandscape = true,
|
47
|
+
maxColumnsBeforeLandscape = 5
|
48
|
+
} = options;
|
49
|
+
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
50
|
+
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
51
|
+
children: [new Paragraph({
|
52
|
+
children: [new TextRun({
|
53
|
+
text: header,
|
54
|
+
size: fontSize,
|
55
|
+
bold: boldHeaders
|
56
|
+
})],
|
57
|
+
alignment: AlignmentType.CENTER
|
58
|
+
})],
|
59
|
+
verticalAlign: VerticalAlign.CENTER
|
60
|
+
}));
|
61
|
+
const tableHeaderRow = new TableRow({ children: headerCells });
|
62
|
+
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
63
|
+
const rowCells = cells.map(
|
64
|
+
(value) => new TableCell({
|
65
|
+
children: [new Paragraph({
|
66
|
+
children: [new TextRun({
|
67
|
+
text: value,
|
68
|
+
size: fontSize
|
69
|
+
})],
|
70
|
+
alignment: AlignmentType.CENTER
|
71
|
+
})],
|
72
|
+
verticalAlign: VerticalAlign.CENTER
|
73
|
+
})
|
74
|
+
);
|
75
|
+
return new TableRow({ children: rowCells });
|
76
|
+
});
|
77
|
+
const table = new Table({
|
78
|
+
rows: [tableHeaderRow, ...rows],
|
79
|
+
width: { size: 11e3, type: WidthType.DXA },
|
80
|
+
indent: { size: -1e3, type: WidthType.DXA }
|
81
|
+
});
|
82
|
+
const doc = new Document({
|
83
|
+
sections: [{
|
84
|
+
children: [table, new Paragraph({ text: "" })],
|
85
|
+
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
86
|
+
}]
|
87
|
+
});
|
88
|
+
Packer.toBlob(doc).then((blob) => {
|
89
|
+
saveAs(blob, `${title}.docx`);
|
90
|
+
});
|
91
|
+
};
|
92
|
+
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
93
|
+
};
|
94
|
+
var WordExport_default = WordExport;
|
95
|
+
|
96
|
+
// utils/exportUtils/exportUtils.ts
|
97
|
+
var generateExcelColumns = (columns, exportCustomColumns) => {
|
98
|
+
let excelColumns = columns.map((column) => ({
|
99
|
+
header: column.title,
|
100
|
+
key: column.field,
|
101
|
+
width: 20
|
102
|
+
}));
|
103
|
+
if (exportCustomColumns) {
|
104
|
+
exportCustomColumns.forEach((custom) => {
|
105
|
+
excelColumns = excelColumns.map(
|
106
|
+
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
107
|
+
);
|
108
|
+
});
|
109
|
+
}
|
110
|
+
return excelColumns;
|
111
|
+
};
|
112
|
+
var applyHeaderStyles = (row, columnCount) => {
|
113
|
+
row.height = 40;
|
114
|
+
row.font = { size: 12, bold: true };
|
115
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
116
|
+
for (let i = 1; i <= columnCount; i++) {
|
117
|
+
const cell = row.getCell(i);
|
118
|
+
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
119
|
+
cell.border = {
|
120
|
+
top: { style: "thin" },
|
121
|
+
left: { style: "thin" },
|
122
|
+
bottom: { style: "thin" },
|
123
|
+
right: { style: "thin" }
|
124
|
+
};
|
125
|
+
}
|
126
|
+
};
|
127
|
+
var applyRowStyles = (row, columnCount) => {
|
128
|
+
row.height = 40;
|
129
|
+
row.font = { size: 12 };
|
130
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
131
|
+
for (let i = 1; i <= columnCount; i++) {
|
132
|
+
const cell = row.getCell(i);
|
133
|
+
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
134
|
+
cell.border = {
|
135
|
+
top: { style: "thin" },
|
136
|
+
left: { style: "thin" },
|
137
|
+
bottom: { style: "thin" },
|
138
|
+
right: { style: "thin" }
|
139
|
+
};
|
140
|
+
}
|
141
|
+
};
|
142
|
+
var generateExcelDataRows = (columns, data) => {
|
143
|
+
return data.map((element) => {
|
144
|
+
const rowData = {};
|
145
|
+
columns.forEach((col) => {
|
146
|
+
const value = element[col.field];
|
147
|
+
rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
|
148
|
+
});
|
149
|
+
return rowData;
|
150
|
+
});
|
151
|
+
};
|
152
|
+
var setColumnAutoWidths = (sheet) => {
|
153
|
+
var _a;
|
154
|
+
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
155
|
+
var _a2;
|
156
|
+
let maxLength = 10;
|
157
|
+
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
158
|
+
const cellValue = cell.value ? String(cell.value) : "";
|
159
|
+
maxLength = Math.max(maxLength, cellValue.length + 5);
|
160
|
+
});
|
161
|
+
column.width = maxLength;
|
162
|
+
});
|
163
|
+
};
|
164
|
+
|
165
|
+
// components/export/ExportExcel.tsx
|
166
|
+
import ExcelJS from "exceljs";
|
167
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
168
|
+
var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
|
169
|
+
const exportExcel = async () => {
|
170
|
+
const workbook = new ExcelJS.Workbook();
|
171
|
+
const sheet = workbook.addWorksheet(title, {
|
172
|
+
pageSetup: {
|
173
|
+
fitToPage: true,
|
174
|
+
fitToHeight: 2,
|
175
|
+
fitToWidth: 1,
|
176
|
+
orientation: "landscape"
|
177
|
+
},
|
178
|
+
headerFooter: {
|
179
|
+
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
180
|
+
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
181
|
+
}
|
182
|
+
});
|
183
|
+
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
184
|
+
sheet.columns = excelColumns;
|
185
|
+
const headerRow = sheet.getRow(1);
|
186
|
+
applyHeaderStyles(headerRow, sheet.columns.length);
|
187
|
+
const dataRows = generateExcelDataRows(columns, excelData);
|
188
|
+
dataRows.forEach((data) => {
|
189
|
+
const row = sheet.addRow(data);
|
190
|
+
applyRowStyles(row, sheet.columns.length);
|
191
|
+
});
|
192
|
+
setColumnAutoWidths(sheet);
|
193
|
+
if (excelData.length > 15) {
|
194
|
+
sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
|
195
|
+
} else {
|
196
|
+
sheet.pageSetup.fitToHeight = 1;
|
197
|
+
}
|
198
|
+
workbook.xlsx.writeBuffer().then((data) => {
|
199
|
+
const blob = new Blob([data], {
|
200
|
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
201
|
+
});
|
202
|
+
const url = window.URL.createObjectURL(blob);
|
203
|
+
const anchor = document.createElement("a");
|
204
|
+
anchor.href = url;
|
205
|
+
anchor.download = `${title}.xlsx`;
|
206
|
+
anchor.click();
|
207
|
+
window.URL.revokeObjectURL(url);
|
208
|
+
});
|
209
|
+
};
|
210
|
+
return /* @__PURE__ */ jsx2("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
211
|
+
};
|
212
|
+
var ExportExcel_default = ExportExcel;
|
213
|
+
|
214
|
+
// components/ExportSection.tsx
|
215
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
216
|
+
var ExportSection = ({
|
217
|
+
wordBtn,
|
218
|
+
excelBtn,
|
219
|
+
downloadSectionLeftSideContent,
|
220
|
+
tableData,
|
221
|
+
columns,
|
222
|
+
tableName,
|
223
|
+
exportCustomColumns,
|
224
|
+
wordOptions
|
225
|
+
}) => {
|
226
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: /* @__PURE__ */ jsxs("div", { className: "ndt-download-section", children: [
|
227
|
+
/* @__PURE__ */ jsx3("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
|
228
|
+
/* @__PURE__ */ jsxs("div", { className: "ndt-download-buttons", children: [
|
229
|
+
wordBtn && /* @__PURE__ */ jsx3(
|
230
|
+
WordExport_default,
|
231
|
+
{
|
232
|
+
wordData: tableData,
|
233
|
+
columns,
|
234
|
+
title: tableName,
|
235
|
+
exportCustomColumns,
|
236
|
+
options: wordOptions
|
237
|
+
}
|
238
|
+
),
|
239
|
+
excelBtn && /* @__PURE__ */ jsx3(
|
240
|
+
ExportExcel_default,
|
241
|
+
{
|
242
|
+
excelData: tableData,
|
243
|
+
columns,
|
244
|
+
title: tableName,
|
245
|
+
exportCustomColumns
|
246
|
+
}
|
247
|
+
)
|
248
|
+
] })
|
249
|
+
] }) });
|
250
|
+
};
|
251
|
+
var ExportSection_default = ExportSection;
|
252
|
+
export {
|
253
|
+
ExportSection_default as ExportSection
|
254
|
+
};
|
package/dist/index.d.ts
CHANGED
@@ -1,88 +1,7 @@
|
|
1
|
-
import React
|
2
|
-
import
|
1
|
+
import React from 'react';
|
2
|
+
import { T as TableProps, D as DataTableRef } from './DataTable.types-H_KYwjEQ.js';
|
3
|
+
export { C as Column, a as TableElement } from './DataTable.types-H_KYwjEQ.js';
|
3
4
|
|
4
|
-
|
5
|
-
[key: string]: string | number;
|
6
|
-
};
|
7
|
-
type TableData = Array<TableElement>;
|
8
|
-
type Column = {
|
9
|
-
field: string;
|
10
|
-
title: string;
|
11
|
-
width?: number;
|
12
|
-
autoinc?: boolean;
|
13
|
-
formatter?: (cell: string, row: TableElement) => ReactElement;
|
14
|
-
exportCustomCell?: (cell: string, row: TableElement) => string;
|
15
|
-
headerFilter?: (headerValue: string, rowValue: string) => string;
|
16
|
-
sortable?: boolean;
|
17
|
-
filterable?: boolean;
|
18
|
-
};
|
19
|
-
type ExportOptions = {
|
20
|
-
fontSize?: number;
|
21
|
-
boldHeaders?: boolean;
|
22
|
-
autoLandscape?: boolean;
|
23
|
-
maxColumnsBeforeLandscape?: number;
|
24
|
-
};
|
25
|
-
type TableProps = {
|
26
|
-
tableData: TableData;
|
27
|
-
columns: Array<Column>;
|
28
|
-
tableName: string;
|
29
|
-
loading?: boolean;
|
30
|
-
loadingElement?: ReactElement | null;
|
31
|
-
isFooter?: boolean;
|
32
|
-
paginationCounts?: Array<number> | null;
|
33
|
-
scrollable?: boolean;
|
34
|
-
scrollHeight?: number;
|
35
|
-
exportCustomColumns?: Array<{
|
36
|
-
header: string;
|
37
|
-
key: string;
|
38
|
-
width: number;
|
39
|
-
}> | null;
|
40
|
-
excelBtn?: boolean;
|
41
|
-
wordBtn?: boolean;
|
42
|
-
downloadSectionLeftSideContent?: ReactElement | null;
|
43
|
-
headerGroup?: Array<{
|
44
|
-
title: string;
|
45
|
-
cols: number;
|
46
|
-
}> | null;
|
47
|
-
groupBy?: string | null;
|
48
|
-
isTitles?: boolean;
|
49
|
-
wordOptions?: ExportOptions;
|
50
|
-
WordExportComponent?: React.ComponentType<{
|
51
|
-
wordData: TableData;
|
52
|
-
columns: Array<Column>;
|
53
|
-
title: string;
|
54
|
-
options?: ExportOptions;
|
55
|
-
exportCustomColumns?: TableProps["exportCustomColumns"];
|
56
|
-
}>;
|
57
|
-
ExportExcelComponent?: React.ComponentType<{
|
58
|
-
excelData: TableData;
|
59
|
-
columns: Array<Column>;
|
60
|
-
title: string;
|
61
|
-
exportCustomColumns?: TableProps["exportCustomColumns"];
|
62
|
-
}>;
|
63
|
-
};
|
64
|
-
type DataTableRef = {
|
65
|
-
getData: () => TableData;
|
66
|
-
getCurrentData: () => TableData;
|
67
|
-
};
|
5
|
+
declare const DataTable: React.ForwardRefExoticComponent<TableProps & React.RefAttributes<DataTableRef>>;
|
68
6
|
|
69
|
-
|
70
|
-
|
71
|
-
type Props$1 = {
|
72
|
-
wordData: TableData;
|
73
|
-
columns: Array<Column>;
|
74
|
-
title: string;
|
75
|
-
options?: ExportOptions;
|
76
|
-
exportCustomColumns?: TableProps["exportCustomColumns"];
|
77
|
-
};
|
78
|
-
declare const WordExport: ({ wordData, columns, title, options }: Props$1) => react_jsx_runtime.JSX.Element;
|
79
|
-
|
80
|
-
type Props = {
|
81
|
-
columns: Array<Column>;
|
82
|
-
excelData: Array<TableElement>;
|
83
|
-
title: string;
|
84
|
-
exportCustomColumns: TableProps["exportCustomColumns"];
|
85
|
-
};
|
86
|
-
declare const ExportExcel: ({ columns, excelData, title, exportCustomColumns }: Props) => react_jsx_runtime.JSX.Element;
|
87
|
-
|
88
|
-
export { type Column, DataTable, ExportExcel, type TableElement, type TableProps, WordExport };
|
7
|
+
export { DataTable, DataTableRef, TableProps };
|
package/dist/index.js
CHANGED
@@ -393,49 +393,8 @@ function useDebouncedEffect(callback, deps, delay) {
|
|
393
393
|
}, [...deps, delay]);
|
394
394
|
}
|
395
395
|
|
396
|
-
// components/ExportSection.tsx
|
397
|
-
import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
398
|
-
var ExportSection = ({
|
399
|
-
wordBtn,
|
400
|
-
excelBtn,
|
401
|
-
downloadSectionLeftSideContent,
|
402
|
-
tableData,
|
403
|
-
columns,
|
404
|
-
tableName,
|
405
|
-
exportCustomColumns,
|
406
|
-
wordOptions,
|
407
|
-
WordExportComponent,
|
408
|
-
ExportExcelComponent
|
409
|
-
}) => {
|
410
|
-
return /* @__PURE__ */ jsx13(Fragment2, { children: /* @__PURE__ */ jsxs5("div", { className: "ndt-download-section", children: [
|
411
|
-
/* @__PURE__ */ jsx13("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
|
412
|
-
/* @__PURE__ */ jsxs5("div", { className: "ndt-download-buttons", children: [
|
413
|
-
wordBtn && WordExportComponent && /* @__PURE__ */ jsx13(
|
414
|
-
WordExportComponent,
|
415
|
-
{
|
416
|
-
wordData: tableData,
|
417
|
-
columns,
|
418
|
-
title: tableName,
|
419
|
-
exportCustomColumns,
|
420
|
-
options: wordOptions
|
421
|
-
}
|
422
|
-
),
|
423
|
-
excelBtn && ExportExcelComponent && /* @__PURE__ */ jsx13(
|
424
|
-
ExportExcelComponent,
|
425
|
-
{
|
426
|
-
excelData: tableData,
|
427
|
-
columns,
|
428
|
-
title: tableName,
|
429
|
-
exportCustomColumns
|
430
|
-
}
|
431
|
-
)
|
432
|
-
] })
|
433
|
-
] }) });
|
434
|
-
};
|
435
|
-
var ExportSection_default = ExportSection;
|
436
|
-
|
437
396
|
// components/DataTable.tsx
|
438
|
-
import { jsx as
|
397
|
+
import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
439
398
|
var DataTable = forwardRef(({
|
440
399
|
tableData,
|
441
400
|
columns,
|
@@ -454,8 +413,7 @@ var DataTable = forwardRef(({
|
|
454
413
|
groupBy = null,
|
455
414
|
isTitles = false,
|
456
415
|
wordOptions,
|
457
|
-
|
458
|
-
ExportExcelComponent
|
416
|
+
ExportSectionComponent
|
459
417
|
}, ref) => {
|
460
418
|
const [filters, setFilters] = useState({});
|
461
419
|
const [sortBy, setSortBy] = useState({ col: "", type: "asc" });
|
@@ -531,9 +489,9 @@ var DataTable = forwardRef(({
|
|
531
489
|
getData: () => processedData,
|
532
490
|
getCurrentData: () => displayData
|
533
491
|
}), [processedData, displayData]);
|
534
|
-
return /* @__PURE__ */
|
535
|
-
|
536
|
-
|
492
|
+
return /* @__PURE__ */ jsxs5("div", { className: "ndt-table-container", children: [
|
493
|
+
ExportSectionComponent && /* @__PURE__ */ jsx13(
|
494
|
+
ExportSectionComponent,
|
537
495
|
{
|
538
496
|
wordBtn,
|
539
497
|
excelBtn,
|
@@ -542,13 +500,11 @@ var DataTable = forwardRef(({
|
|
542
500
|
columns,
|
543
501
|
tableName,
|
544
502
|
exportCustomColumns,
|
545
|
-
wordOptions
|
546
|
-
WordExportComponent,
|
547
|
-
ExportExcelComponent
|
503
|
+
wordOptions
|
548
504
|
}
|
549
505
|
),
|
550
|
-
/* @__PURE__ */
|
551
|
-
/* @__PURE__ */
|
506
|
+
/* @__PURE__ */ jsxs5("div", { className: "ndt-table", children: [
|
507
|
+
/* @__PURE__ */ jsx13(
|
552
508
|
TableHeader_default,
|
553
509
|
{
|
554
510
|
columns,
|
@@ -560,7 +516,7 @@ var DataTable = forwardRef(({
|
|
560
516
|
headerGroup
|
561
517
|
}
|
562
518
|
),
|
563
|
-
loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */
|
519
|
+
loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */ jsx13("span", { style: { marginLeft: 10, fontWeight: "bold" }, children: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445..." }) : /* @__PURE__ */ jsx13(
|
564
520
|
TableBody_default,
|
565
521
|
{
|
566
522
|
tableData: displayData,
|
@@ -574,7 +530,7 @@ var DataTable = forwardRef(({
|
|
574
530
|
isTitles
|
575
531
|
}
|
576
532
|
),
|
577
|
-
isFooter && /* @__PURE__ */
|
533
|
+
isFooter && /* @__PURE__ */ jsx13(
|
578
534
|
TableFooter_default,
|
579
535
|
{
|
580
536
|
paginationCounts,
|
@@ -590,222 +546,6 @@ var DataTable = forwardRef(({
|
|
590
546
|
});
|
591
547
|
DataTable.displayName = "DataTable";
|
592
548
|
var DataTable_default = DataTable;
|
593
|
-
|
594
|
-
// utils/exportUtils/ExportHelpers.ts
|
595
|
-
function prepareExportRows(columns, data) {
|
596
|
-
return data.map(
|
597
|
-
(row) => columns.map((col) => {
|
598
|
-
const value = row[col.field];
|
599
|
-
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
600
|
-
})
|
601
|
-
);
|
602
|
-
}
|
603
|
-
function prepareExportHeaders(columns) {
|
604
|
-
return columns.map((col) => col.title);
|
605
|
-
}
|
606
|
-
|
607
|
-
// components/export/WordExport.tsx
|
608
|
-
import { jsx as jsx15 } from "react/jsx-runtime";
|
609
|
-
var WordExport = ({
|
610
|
-
wordData,
|
611
|
-
columns,
|
612
|
-
title,
|
613
|
-
options = {
|
614
|
-
fontSize: 20,
|
615
|
-
boldHeaders: false,
|
616
|
-
autoLandscape: false,
|
617
|
-
maxColumnsBeforeLandscape: 5
|
618
|
-
}
|
619
|
-
// exportCustomColumns
|
620
|
-
}) => {
|
621
|
-
const createNewWord = async () => {
|
622
|
-
const {
|
623
|
-
AlignmentType,
|
624
|
-
Document,
|
625
|
-
Packer,
|
626
|
-
PageOrientation,
|
627
|
-
// PageOrientation,
|
628
|
-
Paragraph,
|
629
|
-
Table,
|
630
|
-
TableCell,
|
631
|
-
TableRow,
|
632
|
-
TextRun,
|
633
|
-
VerticalAlign,
|
634
|
-
WidthType
|
635
|
-
} = await import("docx");
|
636
|
-
const { saveAs } = await import("file-saver");
|
637
|
-
const {
|
638
|
-
fontSize = 0,
|
639
|
-
boldHeaders = true,
|
640
|
-
autoLandscape = true,
|
641
|
-
maxColumnsBeforeLandscape = 5
|
642
|
-
} = options;
|
643
|
-
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
644
|
-
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
645
|
-
children: [new Paragraph({
|
646
|
-
children: [new TextRun({
|
647
|
-
text: header,
|
648
|
-
size: fontSize,
|
649
|
-
bold: boldHeaders
|
650
|
-
})],
|
651
|
-
alignment: AlignmentType.CENTER
|
652
|
-
})],
|
653
|
-
verticalAlign: VerticalAlign.CENTER
|
654
|
-
}));
|
655
|
-
const tableHeaderRow = new TableRow({ children: headerCells });
|
656
|
-
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
657
|
-
const rowCells = cells.map(
|
658
|
-
(value) => new TableCell({
|
659
|
-
children: [new Paragraph({
|
660
|
-
children: [new TextRun({
|
661
|
-
text: value,
|
662
|
-
size: fontSize
|
663
|
-
})],
|
664
|
-
alignment: AlignmentType.CENTER
|
665
|
-
})],
|
666
|
-
verticalAlign: VerticalAlign.CENTER
|
667
|
-
})
|
668
|
-
);
|
669
|
-
return new TableRow({ children: rowCells });
|
670
|
-
});
|
671
|
-
const table = new Table({
|
672
|
-
rows: [tableHeaderRow, ...rows],
|
673
|
-
width: { size: 11e3, type: WidthType.DXA },
|
674
|
-
indent: { size: -1e3, type: WidthType.DXA }
|
675
|
-
});
|
676
|
-
const doc = new Document({
|
677
|
-
sections: [{
|
678
|
-
children: [table, new Paragraph({ text: "" })],
|
679
|
-
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
680
|
-
}]
|
681
|
-
});
|
682
|
-
Packer.toBlob(doc).then((blob) => {
|
683
|
-
saveAs(blob, `${title}.docx`);
|
684
|
-
});
|
685
|
-
};
|
686
|
-
return /* @__PURE__ */ jsx15("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
687
|
-
};
|
688
|
-
var WordExport_default = WordExport;
|
689
|
-
|
690
|
-
// utils/exportUtils/exportUtils.ts
|
691
|
-
var generateExcelColumns = (columns, exportCustomColumns) => {
|
692
|
-
let excelColumns = columns.map((column) => ({
|
693
|
-
header: column.title,
|
694
|
-
key: column.field,
|
695
|
-
width: 20
|
696
|
-
}));
|
697
|
-
if (exportCustomColumns) {
|
698
|
-
exportCustomColumns.forEach((custom) => {
|
699
|
-
excelColumns = excelColumns.map(
|
700
|
-
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
701
|
-
);
|
702
|
-
});
|
703
|
-
}
|
704
|
-
return excelColumns;
|
705
|
-
};
|
706
|
-
var applyHeaderStyles = (row, columnCount) => {
|
707
|
-
row.height = 40;
|
708
|
-
row.font = { size: 12, bold: true };
|
709
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
710
|
-
for (let i = 1; i <= columnCount; i++) {
|
711
|
-
const cell = row.getCell(i);
|
712
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
713
|
-
cell.border = {
|
714
|
-
top: { style: "thin" },
|
715
|
-
left: { style: "thin" },
|
716
|
-
bottom: { style: "thin" },
|
717
|
-
right: { style: "thin" }
|
718
|
-
};
|
719
|
-
}
|
720
|
-
};
|
721
|
-
var applyRowStyles = (row, columnCount) => {
|
722
|
-
row.height = 40;
|
723
|
-
row.font = { size: 12 };
|
724
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
725
|
-
for (let i = 1; i <= columnCount; i++) {
|
726
|
-
const cell = row.getCell(i);
|
727
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
728
|
-
cell.border = {
|
729
|
-
top: { style: "thin" },
|
730
|
-
left: { style: "thin" },
|
731
|
-
bottom: { style: "thin" },
|
732
|
-
right: { style: "thin" }
|
733
|
-
};
|
734
|
-
}
|
735
|
-
};
|
736
|
-
var generateExcelDataRows = (columns, data) => {
|
737
|
-
return data.map((element) => {
|
738
|
-
const rowData = {};
|
739
|
-
columns.forEach((col) => {
|
740
|
-
const value = element[col.field];
|
741
|
-
rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
|
742
|
-
});
|
743
|
-
return rowData;
|
744
|
-
});
|
745
|
-
};
|
746
|
-
var setColumnAutoWidths = (sheet) => {
|
747
|
-
var _a;
|
748
|
-
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
749
|
-
var _a2;
|
750
|
-
let maxLength = 10;
|
751
|
-
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
752
|
-
const cellValue = cell.value ? String(cell.value) : "";
|
753
|
-
maxLength = Math.max(maxLength, cellValue.length + 5);
|
754
|
-
});
|
755
|
-
column.width = maxLength;
|
756
|
-
});
|
757
|
-
};
|
758
|
-
|
759
|
-
// components/export/ExportExcel.tsx
|
760
|
-
import { jsx as jsx16 } from "react/jsx-runtime";
|
761
|
-
var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
|
762
|
-
const exportExcel = async () => {
|
763
|
-
const ExcelJS = await import("exceljs");
|
764
|
-
const workbook = new ExcelJS.Workbook();
|
765
|
-
const sheet = workbook.addWorksheet(title, {
|
766
|
-
pageSetup: {
|
767
|
-
fitToPage: true,
|
768
|
-
fitToHeight: 2,
|
769
|
-
fitToWidth: 1,
|
770
|
-
orientation: "landscape"
|
771
|
-
},
|
772
|
-
headerFooter: {
|
773
|
-
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
774
|
-
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
775
|
-
}
|
776
|
-
});
|
777
|
-
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
778
|
-
sheet.columns = excelColumns;
|
779
|
-
const headerRow = sheet.getRow(1);
|
780
|
-
applyHeaderStyles(headerRow, sheet.columns.length);
|
781
|
-
const dataRows = generateExcelDataRows(columns, excelData);
|
782
|
-
dataRows.forEach((data) => {
|
783
|
-
const row = sheet.addRow(data);
|
784
|
-
applyRowStyles(row, sheet.columns.length);
|
785
|
-
});
|
786
|
-
setColumnAutoWidths(sheet);
|
787
|
-
if (excelData.length > 15) {
|
788
|
-
sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
|
789
|
-
} else {
|
790
|
-
sheet.pageSetup.fitToHeight = 1;
|
791
|
-
}
|
792
|
-
workbook.xlsx.writeBuffer().then((data) => {
|
793
|
-
const blob = new Blob([data], {
|
794
|
-
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
795
|
-
});
|
796
|
-
const url = window.URL.createObjectURL(blob);
|
797
|
-
const anchor = document.createElement("a");
|
798
|
-
anchor.href = url;
|
799
|
-
anchor.download = `${title}.xlsx`;
|
800
|
-
anchor.click();
|
801
|
-
window.URL.revokeObjectURL(url);
|
802
|
-
});
|
803
|
-
};
|
804
|
-
return /* @__PURE__ */ jsx16("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
805
|
-
};
|
806
|
-
var ExportExcel_default = ExportExcel;
|
807
549
|
export {
|
808
|
-
DataTable_default as DataTable
|
809
|
-
ExportExcel_default as ExportExcel,
|
810
|
-
WordExport_default as WordExport
|
550
|
+
DataTable_default as DataTable
|
811
551
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nillud-data-table",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -11,10 +11,13 @@
|
|
11
11
|
],
|
12
12
|
"exports": {
|
13
13
|
".": {
|
14
|
-
"import": "./dist/index.js"
|
14
|
+
"import": "./dist/index.js",
|
15
|
+
"types": "./dist/index.d.ts"
|
16
|
+
},
|
17
|
+
"./export": {
|
18
|
+
"import": "./dist/export/index.js",
|
19
|
+
"types": "./dist/export/index.d.ts"
|
15
20
|
},
|
16
|
-
"./export/ExportExcel": "./dist/components/export/ExportExcel.js",
|
17
|
-
"./export/WordExport": "./dist/components/export/WordExport.js",
|
18
21
|
"./types": "./dist/index.d.ts",
|
19
22
|
"./styles.css": "./dist/styles.css"
|
20
23
|
},
|
@@ -34,7 +37,7 @@
|
|
34
37
|
"typescript": "^5.8.3"
|
35
38
|
},
|
36
39
|
"scripts": {
|
37
|
-
"build": "tsup && npm run build:styles",
|
40
|
+
"build": "tsup && node postbuild.js && npm run build:styles",
|
38
41
|
"build:styles": "node build-styles.js"
|
39
42
|
}
|
40
43
|
}
|