Home > Back-end >  why is my pdf table printing just one element out of the for loop
why is my pdf table printing just one element out of the for loop

Time:01-18

``

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');


  
}  

`
```

CodePudding user response:

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);
  • Related