todd
todd

Reputation: 335

JsPDF Sub-Array Data Push

I am using Jspdf and Jspdf-autotable to generate PDF in my project. But I couldn't figure out how to push Sub-Array value in row. Here is example of JSON-

[{
            "voucherId":"18010110004",
            "date":"2018-01-01",
            "refNo":"0",
            "narration":null,
            "inWordTk":"Three Thousand  Taka  Only",
            "detailsList":[  
               {  
                  "ledgerName":"Cash",
                  "drAmount":3000,
                  "crAmount":0
               },
               {  
                  "ledgerName":"New Admission Fee Collection",
                  "drAmount":0,
                  "crAmount":3000
               }
            ]
          }
        ]

And i want it to be liked this photo JsPdf

Thanks.

Upvotes: 0

Views: 355

Answers (1)

Simon Bengtsson
Simon Bengtsson

Reputation: 8151

You would simply take out that data first. Something like this in your case:

var header = ['Ledger', 'Debit', 'Credit']
var data = objects.map(obj => Object.values(obj.detailList))
doc.autoTable(header, data)

Upvotes: 1

Related Questions