Complete example of document store rendering would be useful
alisalama opened this issue · 3 comments
Really enjoying this package, but I think a complete example of how to pull a report from the document store and render it on the fly would prove useful.
I've pieced together the below (my working version) from various docs and reading through numerous issues, but it wasn't immediately clear how to do it.
Just a thought...
const jsreport = require('jsreport-core')({ loadConfig: true });
jsreport.init().then(() => {
jsreport.documentStore.collection('templates')
.find({ name: 'ReportXYZ' })
.then((templates) => {
return jsreport.render({
template: templates[0],
data: {
foo: 'world'
}
}).then((resp) => {
// return the response with the pdf
resp.stream.pipe(res);
});
}).catch((e) => {
console.error(e);
});
});
Thank you for suggestion. It is true document store using could be better documented...
Do you know you can also reference the template using name or shortid in the render request? There is no need to explicitly search in document store on your own.
jsreport.render({
template: { name: 'ReportXYZ' },
data: {
foo: "world"
}
})
This will internally do the same as your code in case you have jsreport-templates
applied.
Too late here, but still, I updated the readme a bit to cover this.
Closing