Search code examples
jspdfjspdf-autotable

JsPdf How to add only specific column in a table using JSPdf when we draw HTML table directly to pdf


I want only specific columns from table,but this code gives me the whole table

var doc = new jsPDF('p', 'pt');
doc.text("From HTML", 40, 50);
var res = doc.autoTableHtmlToJson(document.getElementById("basic-table"));
doc.autoTable(res.columns, res.data, {startY: 60});
doc.save('error_log_report.pdf');

I want selected column and respective data in HTML table


Solution

  • The doc.autoTableHtmlToJson(); method returns normal javascript arrays which you can filter. If you only want the first two columns you could do something like this:

    var res = doc.autoTableHtmlToJson(document.getElementById("basic-table"));
    var columns = [res.columns[0], res.columns[1]];
    doc.autoTable(columns, res.data, {startY: 60});