如何在 col header 和 jspdf autotable 中的行之间添加字段名称作为第一行?

How to add a field name as first row in between col header and rows in jspdf autotable?

我需要打印发票..im 使用 jspdf 但我需要在 col header 和行之间添加一个字段作为医生姓名和部门名称..在 jspdf 中可以吗?

demo img

  let col=['Item','Unit','Amt','Discnt','Net Amt','Vat%','VatAmt','Total']; 
  // initialization for headers
  let title = "INVOICE" // title of report
   for(let i=0;i <this.itemForPrint.length;i++)
   {
   row.push(this.itemForPrint[i].itemName);
      row.push(this.itemForPrint[i].unit);
      row.push(this.itemForPrint[i].rate);
      row.push(this.itemForPrint[i].insDiscount);
      row.push(this.itemForPrint[i].amount);
      rowD.push(row);
      }
      this.getReport(col , rowD , title );
      }
      getReport(col: any[], rowD: any[], title: any)
     {
       var pageContent = function (data) {
          // HEADER

          // FOOTER
         var gdate = "Generated on : "+formatDate(new Date(), 'dd/MM/yyyy', 
          'en');
          var str = "Page " + data.pageCount;
          // Total page number plugin only available in jspdf v1.0+
          if (typeof pdf.putTotalPages === 'function') {
              str = str + " of " + totalPagesExp;
          }
          pdf.setFontSize(10);
          var pageHeight = pdf.internal.pageSize.height || 
          pdf.internal.pageSize.getHeight();
          pdf.text(gdate,40, pageHeight - 30);
          pdf.text(str,500, pageHeight - 30); // showing current page number
      };
       pdf.autoTable(col, rowD,
          { addPageContent: pageContent,

              margin: { top: 200 },

          });

对于您的示例,我将包括一个空行,我手动设置使用 minCellHeight 的高度并将 colspan 设置为等于总列数。然后我会使用 didDrawCell 钩子来手动绘制 headers.