[英]Change row background color pdf export dataTable
I 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.我需要检查一列的值是否为负数以及在导出为 PDF 时,如果是,则使整个单元格变为红色或 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.我可以在浏览器中显示背景时修改背景,但在导出时效果不同。
I use http://datatables.net/我使用http://datatables.net/
{
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')
}
}
});
I just posted an answer in the DataTablesforum for a similar question.我刚刚在 DataTables论坛上发布了一个类似问题的答案。 The solution is to modify the table in the PDF document in the customize callback.解决方法是在自定义回调中修改PDF文档中的表格。
buttons: [
{
extend: "pdfHtml5",
customize: function(doc) {
age = table.column(3).data().toArray();
for (var i = 0; i < age.length; i++) {
if (age[i] < 40) {
doc.content[1].table.body[i+1][3].fillColor = 'blue';
}
}
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.