Search code examples
jspdfjspdf-autotable

Different width for each columns in jspdf autotable?


My table has 13 columns. How can I get different width for each column? Can I give each column width like this?

styles: {overflow: 'linebreak' ,columnWidth: [100,80,80,70,80,80,70,70,70,70,60,80,100]},

My table Syntax:

> var res = doc.autoTableHtmlToJson(document.getElementById(tableID)); 
> doc.autoTable(res.columns, res.data, {  styles: {overflow: 'linebreak'
> ,columnWidth: [100,80,80,70,80,80,70,70,70,70,60,80,100]},  startY:
> 60,  bodyStyles: {valign: 'top'},  });

Solution

  • You would have to transform your columnWidth array to look like this:

    autoTable(doc, {
      html: '#table',
      columnStyles: {
        0: {cellWidth: 100},
        1: {cellWidth: 80},
        2: {cellWidth: 80},
        // etc
      }
    });
    

    Note the use of columnStyles instead of styles.