Function to color cells according to content (pdfMake)
Function to color cells according to content (pdfMake)
Jokris
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
This discussion has been closed.
Answers
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)}],
]
}
}
]
}
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