Different width for each column in jspdf automatically?

My table has 13 columns. How can I get a different width for each column? Can I specify the width of each column?

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'},  });
+11
source share
4 answers

You need to convert the columnWidth array so that it looks like this:

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

Pay attention to use columnStylesinstead styles.

+23
source

In a previous release (1.3.4), he could do as shown below:

var columns = [
          {title: "Signum", dataKey: "signum"},
          {title: "Name", dataKey: "name"},
          {title: "Role", dataKey: "role"},
          {title: "Location", dataKey: "location"} 
          ]

But the last one, i.e. 2.3.2, requires the format below

doc.autoTable(colums,data,{
    addPageContent:pageContent,
    margin: {horizontal:5,top: 20},
    startY: 0.47*doc.internal.pageSize.height,
    styles: {overflow: 'linebreak'},
    columnStyles: {
     id: {columnWidth: 25}, 
     name:{columnWidth:40}, 
     role: {columnWidth: 15}, 
     location: {columnWidth: 30}
    }
  });

, , . autotable.js

+5

Say, [steps, methods, process, supplies, results] - all my table headers. If I want to increase or decrease the width of a table,

columnStyles: {
    steps: {columnWidth:215},
    Methods: {columnWidth: 60},
    process: {columnWidth: 100},
    Delivers: {columnWidth: 90},
    Result: {columnWidth: 90}
}

Here you can specify the width of each column.

+3
source

By default, "columnsStyles" do not have in "Options" that you need to create it, and in the next step you define "columnWidth".

Options['columnStyles'] = {
  0: {columnWidth: 50},
  1: {columnWidth: 'auto'},
  2: {columnWidth: 'wrap'},
  3: {columnWidth: 150}
}
JSPDF.autoTable(columns, values, Options)
+1
source

Source: https://habr.com/ru/post/1650288/


All Articles