Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why is my pdf table printing just one element out of the for loop

``

generatePdf() {

this.attendList =this.attendanceList;



for(let i:number=0;i<this.attendList.length; i++){

whenever I generate the pdf table only the first element shows only the first element of the array, can someone please help me


let bod:any[] = [


           [
           
            this.attendList[i].id, this.attendList[i].name, this.attendList[i]

           .status,this.attendList[i].created_date
           ]
      
]
         
          
     this.bodList=bod;
     console.log(this.bodList)
     }



  let text = "";
 




  var pdf = new jsPDF();

  pdf.setFontSize(2);
  pdf.text('Attendace List', 11, 8);
  pdf.setFontSize(12);
  pdf.setTextColor(99);


  (pdf as any).autoTable({
  head: this.header,
  body: this.bodList,
  theme: 'grid',
  didDrawCell: data => {
      // console.log(data.column.index)
  }
  })

  // Open PDF document in browser's new tab
  pdf.output('dataurlnewwindow')

  // Download PDF doc  
  // pdf.save('table.pdf');


  
}  

`
```

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are completely setting the bodlist every loop instead of pushing new items into it.

[1] -> [2] -> [66]

Instead of

[1] -> [1, 2] -> [1, 2, 66]

You want:

let bod:any[] = [       
    this.attendList[i].id, 
    this.attendList[i].name, 
    this.attendList[i].status,
    this.attendList[i].created_date
      
];

this.bodList.push(bod);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading