本文介绍了如何制作多表格标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试合并2个标题的表.目前,我用2个单独的标题制作了2个单独的表格,看起来还不错,但是当表格宽度扩展时,第一个表格标题不会扩展.我如何合并2个标题或我可以用2个表格标题制作1个表格.请看图片(目前有2个表头的桌子如何)

I am trying to make a table with 2 headers merged. At the moment i made 2 seperate tables with 2 seperate headers and it looks okay, but when the table width expands the first table header does not expand. How can i merge the 2 headers or can i make 1 table with 2 tableheaders. Please see picture (how the table is at the moment with 2 tableheaders)

这是我的代码:

function createPDF(){
             /** START PDF INSTANCE */
            //var doc = new jsPDF('p', 'pt');
            var doc = new jsPDF('l', 'pt');
            var row = 80;
            addPdfHeader(doc, row, vm.translate("REPORT.LEGALFORMS ")+" "+vm.activeCompanyYear);

            doc.setFillColor(33, 150, 243);
            var columns = [ "               ",vm.activeCompanyYear,vm.activeCompanyYear-1,vm.activeCompanyYear-2];

            var rows = [];

            var description = "";
            for(var j=0; j<vm.reportData.length; j++){
                var obj = vm.reportData[j];


                description = obj.descriptionEng;

                if(description == "total"){
                    description = vm.translate("REPORT.REGISTRY.TOTAL");
                }

                var singleRow = [description,
                                 obj.year3Total,
                                 obj.year3Local,
                                 obj.year3International,
                                 obj.year2Total,
                                 obj.year2Local,
                                 obj.year2International,
                                 obj.year1Total,
                                 obj.year1Local,
                                 obj.year1International
                               ]
               rows.push(singleRow);
            }

            doc.autoTable(columns, [], {
                theme : 'grid',
                styles: {
                   halign: 'right'
                },
                headerStyles: {
                   fillColor: [33, 150, 243],
                   halign:'center',
                   lineWidth: 1,
                   lineColor: [221, 221, 221]

                },
                columnStyles:{
                     0: {columnWidth: 266}
                },
                margin : {
                  top : 100
                }
            });

            var columns2 = [ vm.translate("MENU.SETTINGS.LEGALFORM"),
                             vm.translate("REPORT.REGISTRY.TOTAL"),
                             vm.translate("REPORT.REGISTRY.LOCAL"),
                             vm.translate("REPORT.REGISTRY.INTERNATIONAL"),
                             vm.translate("REPORT.REGISTRY.TOTAL"),
                             vm.translate("REPORT.REGISTRY.LOCAL"),
                             vm.translate("REPORT.REGISTRY.INTERNATIONAL"),
                             vm.translate("REPORT.REGISTRY.TOTAL"),
                             vm.translate("REPORT.REGISTRY.LOCAL"),
                             vm.translate("REPORT.REGISTRY.INTERNATIONAL")
                            ];

            doc.autoTable(columns2, rows, {
                theme : 'grid',
                styles: {
                   halign: 'right'
                },
                headerStyles: {
                   halign:'center',
                   lineWidth: 1,
                   lineColor: [221, 221, 221]
                },
                margin : {
                  top : 120
                },
                columnStyles:{
                     0: {halign:'left'}
                },
                createdCell: function(cell, data) {
                   if(data.row.raw[0] === vm.translate("REPORT.REGISTRY.TOTAL")) {
                      cell.styles.fontStyle = 'bold';
                      cell.styles.fillColor = [255,251,204];
                   }
                }

            });

            doc.save();
        };

推荐答案

类似的东西(v3及更高版本):

Something like this (v3 and up):

let head = [
    [
        {content: 'People', colSpan: 3, styles: {halign: 'center', fillColor: [22, 160, 133]}},
        {content: 'Data', colSpan: 2, styles: {halign: 'center', fillColor: [22, 160, 133]}}
    ],
    ['ID', 'Name', 'Email', 'City', 'Sum'],
];

doc.autoTable({
    startY: 60,
    head: head,
    body: body,
    theme: 'grid'
});

这篇关于如何制作多表格标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:16