Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsPDF-Autotable blank rows using array with objects

Im trying to fill a Table with an array that contains persons objects, the clg displays the same structure as the example from the plugin github. My array with objects: enter image description here

JsPDF- Autotable Array with Objects: enter image description here

Im setting as row the array var but my table is displaying like this: enter image description here

The table is drawing 3 rows, one for each object, but no data displayed.

This is my pdf generator code

  let genPdf = () => {
var doc = new jsPDF('l', 'pt');
doc.autoTable(cols,rowArray, {
  // Styling
  theme: 'striped', // 'striped', 'grid' or 'plain'
  styles: {overflow: 'linebreak',columnWidth: 'wrap',lineWidth: 1,cellPadding: 2, fontSize: 10 },   
  columnStyles: { text: { columnWidth: 'auto' } },
  headerStyles: {},
  bodyStyles: {},
  alternateRowStyles: {},

  // Properties
  startY: 30, // false (indicates margin top value) or a number
  margin: 40, // a number, array or object
  pageBreak: 'auto', // 'auto', 'avoid' or 'always'
  tableWidth: 'auto', // 'auto', 'wrap' or a number, 
  showHeader: 'everyPage', // 'everyPage', 'firstPage', 'never',
  tableLineColor: 200, // number, array (see color section below)
  tableLineWidth: 0,

  // Hooks

});

doc.setPage(1 + doc.internal.getCurrentPageInfo().pageNumber - doc.autoTable.previous.pageCount);
doc.save('reporte.pdf');}
like image 821
Eduardo Moreno Avatar asked Feb 07 '26 04:02

Eduardo Moreno


1 Answers

i have to create an array to save the objec values and push the object values of the object like this

arrayWithObjects.push(Object.values(p)); 

p it's the new object, inside an addPerson function i wrote the code above and worked enter image description here

enter image description here

I hope it helps someone

like image 127
Eduardo Moreno Avatar answered Feb 08 '26 17:02

Eduardo Moreno