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.
Using FTP and PHP to get an array of file details such as size and…
Creating and using Laravel form requests to create cleaner code, separation and reusability for your…
Improving the default Laravel login and register views in such a simple manner but making…
Laravel validation for checking if a field value exists in the database. The validation rule…