如何在不修改主表的情况下嵌套表

时间:2017-10-20 23:07:18

标签: javascript jspdf jspdf-autotable

大家好我正在使用最新版本的jspdf和jspdf-autotable并且我试图嵌套表在数据占用单个页面时工作正常但是当它们占用更多嵌套表时它们会转到最后一页

enter image description here

此代码打印表

public printTableData() {
    let __self__ = this;
    let extra    = 0, lastDifference = 0, infoPositions = [];
    this.pdfBuilder.autoTable(this.config.columnsTable, this.config.concepts, {
        addPageContent: this.printFooterEachPage.bind(this),
        pageBreak: 'auto',
        drawRow: function (row, data) {
            if(data.cursor.y > 200) {
                // Adding page for the next products
                data.addPage();
                lastDifference = 0;
                data.cursor.y = row.height + data.table.headerRow.height - 1.5;
                row.y = row.height + data.table.headerRow.height - 1.5;
            }
            // This code helps me to separate the rows with the information by product
            let difference = row.height;
            if (row.index > 0 && lastDifference > 0) {
                data.cursor.y = lastDifference;
                lastDifference += difference;
            } else {
                lastDifference = row.y + row.height
            }
            __self__.pdfBuilder.setDrawColor(170, 170, 170);
            __self__.pdfBuilder.setFontStyle('bold');
            __self__.pdfBuilder.setFontSize(10);
            __self__.pdfBuilder.rect(data.settings.margin.left, lastDifference, data.table.width, 28, 'S');
            __self__.pdfBuilder.autoTableText("Product data", data.settings.margin.left + data.table.width / 2, lastDifference + 5, {
                halign: 'center',
                valign: 'middle'
            });

            // Here is the data to position the information by product
            infoPositions.push({
                y: lastDifference,
                index: row.index,
                pageCount: data.pageCount
            });

            lastDifference += 28;
            extra = difference + 28;
        },
        margin: {
            left:  5,
            right: 5,
        },
        startY: 79,
    });

    this.printTaxesInfo(infoPositions);
}

此代码打印每件产品的税收信息

private printTaxesInfo(infoPositions) {
    infoPositions.forEach((infoData) => {
        this.pdfBuilder.autoTable([
            {title: "BASE",         dataKey: "base"},
            {title: "TAX",          dataKey: "tax"},
            {title: "FACTOR",       dataKey: "factor"},
            {title: "RATE OR FEE",  dataKey: "fee"},
            {title: "AMOUNT",       dataKey: "amount"},
        ], this.config.concepts[infoData.index].taxes, {
            margin: {
                left:  130,
            },
            tableWidth: 80,
            startY: infoData.y + 5
        });
    });
}

如何在没有这些问题的情况下嵌套表格?谢谢。

0 个答案:

没有答案