styling background color in print in search filtering
styling background color in print in search filtering
Hi, the link https://datatables.net/forums/discussion/79772/styling-background-color-in-print
That I have work around with display background color on each cell.
But there is other problem.
In the search function, when you type as the datatable will perform reduce the row which you can see screenshow as Showing 1 to 8 of 8 entries (filtered from 227 total entries)
When I click print, the background color is not the match to the value as it went mixed up like glitch.
I've research and I realise the color only run 1 to 8 rows out of 227 row to display on filtered search in print.
I wonder if you can help how to correct the background color on print?
Answers
I can customize the background color on cell no problem. Just search filter I need help with.
How are you applying the background colour? Can you link to an example please?
Allan
customize: function (doc, row) {
//header color
$(doc.document.body)
.find("table thead tr th")
.addClass(
"datatable-header-background-color",
);
},
Note, the CodeColor() is the function that match the value (switch) which it will use the css for background-color.
So when you input search function. it show what I need to look. But when in print. it show different color background that not match to value.
By the way in previous post that I have problem with bootstrap4 and found other way to bypass it but this is search filtering.
Look like I've found a way to use rows and every function.
var _table = $("#example").DataTable();
_table.rows({
search: "applied",
})
.every(function (
rowIdx,
tableLoop,
rowLoop,
) {
(how to insert background color on specific column)
});
So only thing is how to addClass on speciifc column on bold above.
Use
cell().node()
. You have the row index fromrowIdx
and you know your column index, so:should hopefully do it.
Allan
did use this and it return error:
TypeError: Cannot read properties of undefined (reading 'classList')
If you can link to a page showing the issue I can take a look and see what is going wrong.
Thanks,
Allan
Hi allan,
I have working on it all day. So I found a way to use rowLoop
_table.rows({
search: "applied",
})
.every(function (
rowIdx,
tableLoop,
rowLoop,
) {
$(doc.document.body)
.find(
"table tbody tr:nth-child(" +
(rowLoop + 1) + // rowLoop is depend row in loop. ** Do not use rowIdx which is start from begin.
") td:nth-child(4)",
)
.addClass(CodeColor(_table.cell(i, 3).data()));
),
);
});