-1

I'm currently using json2Csv for exporting data in csv table.

The data is exported correctly but I want to add footer row which will calculate total price.

The link is down below and in footer I want to get the total for prices: https://stackblitz.com/edit/angular-json2csv

In documentation there is nothing about adding row with totals (or footer row). Does anybody know how to add that?

Many thanks!

Yuniku_123
  • 269
  • 1
  • 5
  • 18

1 Answers1

0

Not sure if there is a more official way to do this but this works: This is how I would format the data if I was writing the CSV by hand. You're just telling it which columns your footers belong in.

downloadFile(){
  const cars = _.clone(this.myCars);
  cars.push({car: 'total', price : _.sumBy(cars, 'price')});
  return this.downloadService.downloadFile(cars)
}

You'll need to pull in lodash to use this answer: https://lodash.com/docs/4.17.15

Stackblitz Link

Damian C
  • 2,111
  • 2
  • 15
  • 17