Skip to content

Commit

Permalink
Merge pull request #1 from MrRio/master
Browse files Browse the repository at this point in the history
Fix: Wrong TypeScript type in jsPDF.table (parallax#3086) (parallax#3087)
  • Loading branch information
sthagen committed Feb 10, 2021
2 parents 3592fc2 + c91995d commit faeb8d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/modules/cell.js
Expand Up @@ -442,7 +442,7 @@ import { jsPDF } from "../jspdf.js";
});
}

if (autoSize) {
if (autoSize || (Array.isArray(headers) && typeof headers[0] === "string")) {
var headerName;
for (i = 0; i < headerNames.length; i += 1) {
headerName = headerNames[i];
Expand Down
Binary file added test/reference/table-autoSize-headerNames.pdf
Binary file not shown.
28 changes: 25 additions & 3 deletions test/specs/cell.spec.js
Expand Up @@ -71,16 +71,18 @@ describe("Module: Cell", () => {
}));
}

var header = createHeaders([
var headerNames = [
"coin",
"game_group",
"game_name",
"game_version",
"machine",
"vlt"
]);
];

it("table", () => {
var header = createHeaders(headerNames);

it("table with CellConfig[]", () => {
var doc = new jsPDF({
putOnlyUsedFonts: true,
orientation: "landscape",
Expand All @@ -90,6 +92,26 @@ describe("Module: Cell", () => {
comparePdf(doc.output(), "table.pdf");
});

it("table with string[] and without autoSize", () => {
var doc = new jsPDF({
putOnlyUsedFonts: true,
orientation: "landscape",
floatPrecision: 2
});
doc.table(1, 1, generateData(100), headerNames);
comparePdf(doc.output(), "table-autoSize-headerNames.pdf");
});

it("table with string[] and autoSize", () => {
var doc = new jsPDF({
putOnlyUsedFonts: true,
orientation: "landscape",
floatPrecision: 2
});
doc.table(1, 1, generateData(100), headerNames, { autoSize: true });
comparePdf(doc.output(), "table-autoSize-headerNames.pdf");
});

it("table-autoSize", () => {
var doc = new jsPDF({
putOnlyUsedFonts: true,
Expand Down
18 changes: 15 additions & 3 deletions types/index.d.ts
Expand Up @@ -563,6 +563,18 @@ declare module "jspdf" {
y: number;
}

export interface TableConfig {
printHeaders?: boolean;
autoSize?: boolean;
margins?: number;
fontSize?: number;
padding?: number;
headerBackgroundColor?: string;
css?: {
"font-size": number;
};
}

export interface CellConfig {
name: string;
prompt: string;
Expand Down Expand Up @@ -981,9 +993,9 @@ declare module "jspdf" {
table(
x: number,
y: number,
data: any,
headers: string[],
config: any
data: { [key: string]: string }[],
headers: string[] | CellConfig[],
config: TableConfig
): jsPDF;
calculateLineHeight(
headerNames: string[],
Expand Down

0 comments on commit faeb8d3

Please sign in to comment.