With the following code: stackblitz here
itemsArray = [
{ id : 'A1', name : 'Name A1'},
{ id : 'B2', name : 'nameB2'},
{ id : 'A3', name : 'nameA3'},
{ id : 'A2', name : 'nameA2'},
{ id : 'B1', name : 'nameB1'},
];
constructor() {
pdfMake.vfs = pdfFonts.pdfMake.vfs;
}
getItems(): void {
this.items = _.orderBy(
this.itemsArray,
item => [ item.id, ],
['asc']
);
this.groupedItems = _.groupBy( this.items, item => [ item.id.substring(0,1)] );
}
buildTableBody(data, columns): any {
const body = [];
body.push(columns);
data.forEach((row) => {
const dataRow = [];
columns.forEach((column) => {
if (column.text === 'id')
{
dataRow.push(row['id']);
}
else if (column.text === 'name')
{
dataRow.push(row['name']);
}
});
body.push(dataRow);
});
return body;
}
table(data, columns): any {
return {
table: {
headerRows: 1,
body: this.buildTableBody(data, columns),
},
};
}
createPdf(): void {
this.getItems();
console.log(this.groupedItems);
const dd = {
content: [
this.table(
this.items,
[{ text: 'id'}, { text: 'name'}],
),
],
};
pdfMake.createPdf(dd).open();
}
I got the below result
But could not find a way to split the data groups, where each group should start on a new page:
group A:
group B:
Does someone can help on this ?


