Datatables customize print button

Datatables customize print button

gezergezer Posts: 4Questions: 2Answers: 0

Hello ,
I have a datatable populated with data from jsf.
The width and the alignment of the columns are perfect on the screen, but I cannot print the same when using print button . The columns are defined with :
"columnDefs": [
{ className: "dt-body-center","width": "3%", "targets": [ 0 ] },
{ className: "dt-body-left","width": "31%","targets": [ 1 ] },
{ className: "dt-body-center","width": "4%", "targets": [ 2 ] },
{ className: "dt-body-center","width": "4%", "targets": [ 3 ] },
{ className: "dt-body-center","width": "3%", "targets": [ 4 ] },
{ className: "dt-body-center","width": "3%", "targets": [ 5 ] },
{ className: "dt-body-center","width": "3%", "targets": [ 6 ] },
{ className: "dt-body-left","width": "37%", "targets": [ 7 ] },
{ className: "dt-body-right","width": "3%", "targets": [ 8 ] },
{ className: "dt-body-right","width": "3%", "targets": [ 9 ] },
{ className: "dt-body-right","width": "3%", "targets": [ 10 ] },
{ className: "dt-body-right","width": "3%", "targets": [ 11 ] }
]

Can anybody help me how to print the table with the above settings ?
Thanks in advance

Answers

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    You have you use the customize method of the print button type to customize the output. The settings and classes are not automatically applied to the exported print table.

    Allan

  • gezergezer Posts: 4Questions: 2Answers: 0

    Thank you Allan,
    when i use customize method like:
    customize: function ( win1 ) {
    $(win1.document.body)
    .prepend('

    ' +'XXXX' +'
    '+ value1+'
    '+tvalue2+'

    ')
    .append('

    '+'
    ' +'
    '+'
    '+'
    '+'YYYYY' +'
    ' +'
    '+ value3+'
    '+ value4+'

    ')
    $(win1.document.body).find( 'table' )
    css( "color","red")
    },
    "columnDefs": [
    { className: "dt-body-center","width": "3%", "targets": [ 0 ] },
    { className: "dt-body-left","width": "31%","targets": [ 1 ] },
    { className: "dt-body-center","width": "4%", "targets": [ 2 ] },
    { className: "dt-body-center","width": "4%", "targets": [ 3 ] },
    { className: "dt-body-center","width": "3%", "targets": [ 4 ] },
    { className: "dt-body-center","width": "3%", "targets": [ 5 ] },
    { className: "dt-body-center","width": "3%", "targets": [ 6 ] },
    { className: "dt-body-left","width": "37%", "targets": [ 7 ] },
    { className: "dt-body-right","width": "3%", "targets": [ 8 ] },
    { className: "dt-body-right","width": "3%", "targets": [ 9 ] },
    { className: "dt-body-right","width": "3%", "targets": [ 10 ] },
    { className: "dt-body-right","width": "3%", "targets": [ 11 ] }
    ]
    },
    the button is not working. What am i doing wrong ?

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Not sure from the above I'm afraid. I'd need a link to a test case showing the issue.

    Allan

This discussion has been closed.