I'm currently trying to use the docx javascript library to create a table based on data I have stored in a list. I need to be able to dynamically add more rows to the table depending on the amount of data I have to populate the table but I'm not sure if this is possible.
The way I understand the library is that you need to define the entire table in one line meaning that trying to insert a for-loop to create the number of rows I need would be impossible but I have to imagine that there's a work-around otherwise this library really hasn't been developed with what I imagine is a pretty common use case.
If anyone who has experience using this library has a solution or advice I'd really appreciate some guidance.
Below is the section of code that this post concerns.
this.getPersonnelByLocation('Onsite GTA').forEach(record => {
new TableRow({
height: {height: 500, rule: HeightRule.ATLEAST},
children: [
new TableCell({children: []}),
new TableCell({
new Paragraph({
children: [
new TextRun({
text: record['resourceRole'],
size: 24,
color: 'black',
bold: true
})
]
})
}),
new TableCell({children: []}),
new TableCell({children: []})
]
})
}),