Exporting Datatable to PDF
Exporting Datatable to PDF
Trying to use the export feature on Datatables and I need it to render HTML. So I found this library https://www.npmjs.com/package/html-to-pdfmake which works with PDFMake. But when I'm trying to use it my exported data just shows [object Object].
exportOptions: {
format: {
body: function (data, row, column, node) {
if(column === 1)
{
console.log(JSON.stringify(htmlToPdfmake(data)[0]));
}
return column === 1 ? htmlToPdfmake(data)[0] : data;
}
}
I tried debugging here
http://pdfmake.org/playground.html
using the console output
{"text":"Hello world","nodeName":"B","bold":true,"style":["html-b"]},
And this seems to work in the playground but not in the datatables export. I either get the literal string or [object Object]
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi Colin,
Thank you for the response, I was in the middle of adding a test case but it took me a minute to find out how to get the buttons to show up on live.datatables
http://live.datatables.net/radoruye/1/edit?html,js,console,output
I want the Position column to output HTML but I'm not sure what's wrong. If I do something like
it seems to work fine.
Thanks for the test case, I'm not too sure on that. This thread might - it's showing how to make links - so not the same but still HTML content. This might point in the right direction, if not, let us know,
Colin
Thank you! I think I got it working - fingers crossed for all use cases. I had to use the customize method in order to get this working
But additionally, in my case I still had to use exportOptions to get the data with the tags (not sure if there is a better way to do this, already set stripHtml flag to false)
Then I would just pass
in my customize method.
Anyway, thank you for the help @Colin and I hope this helps others
Updated test case here
http://live.datatables.net/radoruye/4/edit