I want to highlight specific rows while printing data from the jquery data table. I added a class to those rows by createdRow
and added some CSS style to that class. Now I want to keep that styling on those rows while printing.
The code I've used to add class
"createdRow": function (row, data, dataIndex) {
var date = new Date(data.dateOfReg);
var days = datediff(date, new Date());
if (days >= 30 && parseInt(data.received) < 2000 && parseInt(data.payment) >= 2000) {
$(row).addClass('d-flag');
}
}
In the image, you can see some rows have a background color. I just want to keep that while printing data.
CodePudding user response:
Well, I find a solution for this by looping through on customize
callback function something like this -
customize: function (win) {
$(win.document.body).find('table tbody tr').each(function (index) {
var dateOfReg = $(this).find('td:eq(3)').text();
var date = new Date(dateOfReg.split('-')[2], dateOfReg.split('-')[1], dateOfReg.split('-')[0]);
var payment = $(this).find('td:eq(5)').text();
var received = $(this).find('td:eq(6)').text();
var days = datediff(date, new Date());
if (days >= 30 && parseInt(received) < 2000 && parseInt(payment) >= 2000) {
$(this).css('background-color', '#e4e4e4');
}
});
});