Highlighting the max and min column in a table made with DataTables.
Finding the last vale which is the lowest (red) is done by counting the array and finding the index that is length – 1
$("#the-table-id").DataTable({
paginate: false,
bFilter: false,
bInfo: false,
scrollX: true,
initComplete: function () {
let api = this.api();
api.columns(":not(:first)").every(function () {
let col = this.index();
let data = this.data()
.unique()
.map(function (value) {
return parseInt(value);
})
.toArray()
.sort(function (a, b) {
return b - a;
});
let length = data.length;
api.cells(null, col).every(function () {
let cell = parseInt(this.data());
if (cell === data[0]) {
$(this.node()).css("background-color", "rgb(172, 240, 172)");
} else if (cell === data[length - 1]) {
$(this.node()).css("background-color", "rgba(255, 85, 85, 0.32)");
}
});
});
}
});
CodePen example:
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Some early September spring shots from a bushwalk, It is still too early for wildflowers.
I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…
If you ever needed a simple solution in Laravel to delete an entire directory and…
How to enforce only one user to register or be registered in a Laravel web…