Function to color cells according to content (pdfMake)

Function to color cells according to content (pdfMake)

JokrisJokris Posts: 5Questions: 2Answers: 0

How would you do customize function to pdfmake to color content of cells where value equals specific string?
Like If table cell contains 'tomato', color that cell red when printed out.

$('#myTable').DataTable( {
    buttons: [
        'pdfHtml5'
    ]
} );

This question has an accepted answers - jump to answer

Answers

  • JokrisJokris Posts: 5Questions: 2Answers: 0

    I have received this code example but have not figured out how to implement it in code above

    var getCellColor = function(number) {
    if (number === 0) {
    return 'green';
    } else if (number > 0) {
    return 'blue';
    } else {
    return 'red';
    }
    }

    var dd = {
    content: [
    {
    table: {
    body: [
    ['Item', 'Number'],
    ['Item 1', {text: 5, fillColor:getCellColor(5)}],
    ['Item 2', {text: -5, fillColor:getCellColor(-5)}],
    ['Item 3', {text: 12, fillColor:getCellColor(12)}],
    ['Item 4', {text: 0, fillColor:getCellColor(0)}],
    ]
    }
    }
    ]
    }

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    For details on how to use the pdfmake library's API you'd need to refer to the pdfmake documentation or their own support channels.

    Allan

This discussion has been closed.