Skip to content

Commit

Permalink
nicer pdf exports
Browse files Browse the repository at this point in the history
  • Loading branch information
zsuffad committed Jan 28, 2025
1 parent d99a7d3 commit 98843cb
Showing 1 changed file with 59 additions and 16 deletions.
75 changes: 59 additions & 16 deletions packages/tabulator-table/src/tabulator-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ export class TabulatorTable extends ScopedElementsMixin(DBPLitElement) {
break;
}
case 'pdf': {
// Get only displayed columns. [respect Column setting modal state]
let columns = this.tabulatorTable.getColumns();
let header = [];
for(let column of columns) {
Expand All @@ -489,17 +490,35 @@ export class TabulatorTable extends ScopedElementsMixin(DBPLitElement) {
let body = [];
for (let entry of data) {
let entry_array = [];
Object.values(entry).forEach(value => {
entry_array.push(value);

header.forEach(column => {
let cellValue = entry[column] ? entry[column] : '-';
if (Array.isArray(cellValue)) {
cellValue = cellValue.join(', ');
}
entry_array.push(cellValue);
});
body.push(entry_array);
}
let new_table = {
head: [header],
body: body,
};
const doc = new jsPDF();
autoTable(doc, new_table);
const doc = new jsPDF('l', 'pt');
doc.autoTable(header, body, {
horizontalPageBreak: false,
// horizontalPageBreakBehaviour: 'immediately',
tableWidth: 'auto',
styles: {
overflow: 'linebreak',
valign: 'middle',
cellWidth: 'auto'
},
headStyles: {
// cellWidth: 'auto'
},
bodyStyle: {
// cellWidth: 'auto',
overflow: 'linebreak'
}

});
doc.save(dataName);
break;
}
Expand All @@ -524,6 +543,9 @@ export class TabulatorTable extends ScopedElementsMixin(DBPLitElement) {
for (let cell of cells) {
let column = cell.getColumn();
let definition = column.getDefinition();
if (!definition.visible) {
continue;
}
let field = cell.getField();
if(field !== 'empty' && field !== 'undefined' && definition.formatter !== 'html') {
entry[field] = cell.getValue();
Expand All @@ -544,24 +566,45 @@ export class TabulatorTable extends ScopedElementsMixin(DBPLitElement) {

for(let column of columns) {
let definition = column.getDefinition();
if (!definition.visible) {
continue;
}
let field = column.getField();
if(field !== 'empty' && field !== 'undefined' && definition.formatter !== 'html')
header.push(column.getField());
}
let body = [];
for (let entry of selected_data) {
let entry_array = [];
Object.values(entry).forEach(value => {
entry_array.push(value);

header.forEach(column => {
let cellValue = entry[column] ? entry[column] : '-';
if (Array.isArray(cellValue)) {
cellValue = cellValue.join(', ');
}
entry_array.push(cellValue);
});
body.push(entry_array);
}
let new_table = {
head: [header],
body: body,
};
const doc = new jsPDF();
autoTable(doc, new_table);
const doc = new jsPDF('l', 'pt');
doc.autoTable(header, body, {
horizontalPageBreak: false,
// horizontalPageBreakBehaviour: 'immediately',
tableWidth: 'auto',
styles: {
overflow: 'linebreak',
valign: 'middle',
cellWidth: 'auto'
},
headStyles: {
// cellWidth: 'auto'
},
bodyStyle: {
// cellWidth: 'auto',
overflow: 'linebreak'
}

});
doc.save(dataName);
break;
}
Expand Down

0 comments on commit 98843cb

Please sign in to comment.