2016-08-01 38 views
1

我將引導表插件與表導出插件(https://github.com/hhurz/tableExport.jquery.plugin)一起使用。Bootstrap-table將標題添加到PDF導出

我設法導出我的表,但我想在表格本身之前在PDF中添加一個標題。這裏是我的代碼:

$("#table").bootstrapTable({ 
    exportOptions: { 
     fileName: 'export_anim', 
     worksheetName: 'table', 
     csvSeparator: ';', 
     jspdf: { 
      orientation: "l", 
      autotable: { 
       styles: {rowHeight: 14, fontSize: 8, fillColor: 240}, 
       headerStyles: {fillColor: 255, textColor: 0}, 
       alternateRowStyles: {fillColor: 210, textColor: 0} 
      } 
     } 
    } 
}); 

有沒有什麼辦法可以做到這一點?

回答

0

執行此操作的一種方法是將beforePageContent掛鉤與margin選項一起用於自動選項。像這樣的東西:

autotable: { 
    margin: {top: 80}, 
    beforePageContent: function (data) { 
     var doc = data.doc; // Internal jspdf instance 
     doc.setFontSize(20); 
     doc.setTextColor(40); 
     doc.setFontStyle('normal'); 
     doc.text("Table Title", data.settings.margin.left, 60); 
    } 
} 

請注意,您需要jspdf-autotable >=2.0.33。欲瞭解更多信息,請查看自動頁眉和頁腳democode

+0

謝謝,但它說「文檔」沒有定義,我不知道如何以及在哪裏可以通過插件定義它 – Rinku

+0

我的不好!我會用修復程序更新'jspdf-autotable',我會在幾分鐘內回覆您。 –

+0

不錯,謝謝!我會繼續等待,慢慢來:) – Rinku