Skip to content

Commit

Permalink
fix(table): throwing error when header row was enabled on a table wit…
Browse files Browse the repository at this point in the history
…h multiple columns
  • Loading branch information
schoero committed Nov 16, 2023
1 parent 5462c27 commit b096a51
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pdf/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export class Table {
const tableAlign = this.data.align ? this.data.align : undefined;
const tableVerticalAlign = this.data.verticalAlign ? this.data.verticalAlign : "top";

const headerRowIndex = this.data.rows.findIndex(row => !!row.header);

const autoRowHeights: number[] = [];

for(let layer: TableLayer = 0; layer < Object.keys(TableLayer).length; layer++){
Expand Down Expand Up @@ -314,10 +316,10 @@ export class Table {
rowY = doc.y;

// Insert header
const headerRow = this.data.rows.find(row => row.header);
const headerRow = this.data.rows[headerRowIndex];
if(headerRow !== undefined){
this.data.rows.splice(rowIndex, 0, headerRow);
autoRowHeights.splice(rowIndex, 0, autoRowHeights[this.data.rows.indexOf(headerRow)]);
autoRowHeights.splice(rowIndex, 0, autoRowHeights[headerRowIndex]);
rowIndex--;
continue rowLoop;
}
Expand All @@ -328,7 +330,7 @@ export class Table {
// Switch page before overflowing rows and header rows
if(layer > TableLayer.PageInjection){
if(
!!row.header && rowY !== doc.page.margins.top ||
!!row.header && rowY !== (doc.page.margins.top ?? 0) && rowIndex !== headerRowIndex ||
rowY + rowHeight >= doc.page.height - doc.page.margins.bottom
){
doc.switchToPage(this.getCurrentPage(doc) + 1);
Expand Down

0 comments on commit b096a51

Please sign in to comment.