Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Change row background color pdf export dataTable #383

Description

@VitorBenjamin

need to check if the value of a column is negative and at the time of exporting to PDF, and if so, make that whole cell turn red or text-decoration: line-through.

However I do not know how to access the elements to make such a modification.

I can modify the background when it is being displayed in the browser but when exporting it does not work the same way.

{
extend: 'pdfHtml5',
footer: true,
text: 'PDF',
header: true,
title: t,
orientation: 'landscape',
exportOptions: {
rows: function ( idx, data, node ) {
//node.attributes.style = {background-color: "#000";};
//console.log(node.attributes.style);
//return true;
// return data[2] === 'London' ?
// true : false;
}
},
customize: function(doc) {

        doc.content.splice( 1, 0, {
            margin: [ 0, 0, 0, 0 ],
            alignment: 'center',
            image: base64
        } );
        doc.defaultStyle.fontSize = 10;
        doc.pageMargins = [20,10,10,10];
        doc.styles.tableHeader.fontSize = 14;
        doc.styles.title.fontSize = 12;
        // Remove spaces around page title
        doc.content[0].text = doc.content[0].text.trim();
    } 

},
{
    extend: 'print',
    footer: true,
}

],

fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    var valor = aData[3].split('$');
    //console.log(teste);
    if (parseInt(valor[1])<0) { 
        $(nRow).css('background-color', '#e96464')
    }else{
        $(nRow).css('background-color', '#cdedc1')
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions