Export PDF with custom format : problem of decoding html

Export PDF with custom format : problem of decoding html

Delirium6Delirium6 Posts: 10Questions: 1Answers: 1
edited June 2023 in Free community support

Hello,

I see this documentation https://datatables.net/extensions/buttons/examples/html5/outputFormat-function.html
of how customize the export for a column.
So i tried and it works but i'm encounter a new problem of html code.

I have this to export in pdf :
buttons: [ { extend: 'pdfHtml5', footer: true, orientation: 'landscape', exportOptions:{ format: { body: function ( data, row, column, node ) { return (column === 10 ? (data==1?'Oui':'') : data); } }, }, } ],

But if i have a quote a column, i got Cal'enzana and not Cal'enzana in the pdf.
Do i need to decode ? There is simple way with DataTable to do it ?

Regards

Replies

  • Delirium6Delirium6 Posts: 10Questions: 1Answers: 1

    I tried with a test case, but i don't reproduce the problem :
    https://live.datatables.net/femahudo/1/edit

    Any idea ?

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Where does your data come from, ie, Ajax, Javascript HTML?

    If Ajax or Javascript then update the test case to use a sample of the data using Javascript loading like this example.

    If HTML then right click and inspect the cell to see what the cell contains.

    Do i need to decode ? There is simple way with DataTable to do it ?

    Likely you will need to decode it. There is nothing built into Datatables for this. Possibly using Orthogonal data for export will help.

    Kevin

  • Delirium6Delirium6 Posts: 10Questions: 1Answers: 1
    edited June 2023

    Hello,

    Thank's Kevin
    I have update my test case, but i use Laravel framework with https://github.com/yajra/laravel-datatables

    So it's a server side processing.

    Orthogonal export doesn't work.
    If i inpect the cell, i have the quote decoded, but i think it's not decode in the data of the datatable.

    I found a solution to decode with jquery : decodeHTMLEntities(data)

    and this function :

                function decodeHTMLEntities(text) {
                    return $("<textarea/>")
                        .html(text)
                        .text();
                }
    

    It works nice, but if someone have a better solution i will take it.

    Regards

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Yup that will work, but it will be slow for large data sets. That said, I'm not sure I have a better solution for you at this time.

    Allan

Sign In or Register to comment.