var externalDataRetrievedFromServer = [ { name: 'Bartek', age: 34 }, { name: 'John', age: 27 }, { name: 'Elizabeth', age: 30 }, ]; function buildTableBody(data, columns) { var body = []; body.push(columns); data.forEach(function(row) { var dataRow = []; columns.forEach(function(column) { dataRow.push(row[column].toString()); }) body.push(dataRow); }); return body; } function table(data, columns) { return { table: { headerRows: 1, body: buildTableBody(data, columns) } }; } var dd = { content: [ { text: 'Dynamic parts', style: 'header' }, table(externalDataRetrievedFromServer, ['name', 'age']) ] }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter