button pdf, print

button pdf, print

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

I have in the Datatables instead of Male and Female an Icon and if they is a member of a listed group a check icon instead of 1.
if I want to export the table via print pdf the columns are empty. Is it possible to render the field to the icons if someone click on the Buttons? The icons are fontawesome and render into the table.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Yes, you can use orthogonal data or a formatting function.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I am not sure that I understand the example. I believe, I have already written that with the render option in the Datatables, see the gender part.

            "columns":[
                { data: null, render: function (data, type, row){
                        return data.lastname + ' ' + data.firstname;
                    }, sort: "data.lastname"
                },
                { data: "gender", width: '3%', render(data, type, row){
                    return (data == 'MALE')? '<i class="fa fa-male text-maroon" aria-hidden="true"></i>' : '<i class="fa fa-female text-fuchsia" aria-hidden="true"></i>';
                    }, orderable: false, className: 'text-center'
                },
                { data: "birthdate", width: '4%', render(data, type, row){
                        return ageGroup(data);
                    }, className: 'text-center'
                },
    

    The export button should take the Table that is defined. But in the gender Column, is always empty on the exported pages. The icons fa-male and fa-female are not exported

    Andreas

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    I'd need to be able to see the page to be able to debug it.

    Thanks,
    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    here the debug link:

    http://debug.datatables.net/ozikog

    Andreas

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    I'm afraid in this case I would need to be able to see a page rather than the debug trace.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I Send you a message to the link

    Andreas

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Thanks for the links in the PM.

    Looking at the page I see the issue now. You are indeed using a rendering function for the gender column, which is always returning an HTML i element. Buttons strips HTML by default, which explains why you see nothing in the exported file.

    As I mentioned above you need to use the orthogonal export options for Buttons, and then in your rendering function simply do:

    if ( type === 'export' ) {
      return data === 'MALE' ? 'M' : 'F';
    }
    

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    Thanks, now I understand it. Is it possible for export to set a different font, the value to the center or a fontcolor in the cell?

    Andreas

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Yes - you would use the customize callback to modify the generated XML for the XLSX file.

    Allan

This discussion has been closed.