Thanks for your help! I’ve managed to create a component button that will produce and download a CSV file thanks to the above information.
I struggled with parsing an object into a CSV string but found Papa parse which is doing a bang up job.
My last hurdle is working out how to do this in a model method like you mentioned. The only way I can get it to work at the minute is by explicitly iterating on the model in the component controller which means it isn’t very flexible:
export default Component.extend({
download: service('download'),
model: null,
conData: computed('model', function() {
let newArray = [];
this.get('model').forEach(function(x) {
let newData = {
name: x.data.name,
age: x.data.age
}
newArray.push(newData)
})
return newArray
}),
actions: {
request() {
let csvArray = Papa.unparse(this.get('conData'))
this.get('download').asCSV('GeneratedReport.csv', csvArray)
}
}
});
The only thing I’vve done with models so far is to populate them from a JSON return.