I have a DataTable table with 96 time periods. When a period is used its value is 1, otherwise is 0. I want to hide all columns in which all values are 0. I found how to hide a specific column, but I can not get all values in a column in order to decide should I hide it or not. Here is my code snippet:
function colorSchedulePlanCells() {
debugger;
$("#schedulePlanDiv").dataTable().fnSetColumnVis( 5, false );
var rows = $("#schedulePlanDiv").dataTable().fnGetNodes();
for (var i = 0; i < rows.length; i++) {
var isDriver = $(rows[i]).find("td:eq(3)").html();
for (var k = 0; k < rows[i].cells.length; k++) {
var cell = $(rows[i]).find("td:eq(" + k + ")");
if (cell.html() == 1) {
if (!empty(isDriver)) {
customColor = "#fb96b0";
} else {
customColor = "#99edc3";
}
cell.css("background-color", customColor);
} else {
cell.css("background-color", "#D9DDDC");
}
}
}
}
At this moment it colors my cells and hide the sixth column. But how can I hide all columns with all values equals 0 in them?
I made a compromise option - above every column there is 'x' and when you click on it, the column is hidden. Here it is the code for this functionality:
$(document).on("click", ".toggle-vis", function () {
$('a.toggle-vis').on( 'click', function (e) {
e.preventDefault();
$("#schedulePlanDiv").dataTable().fnSetColumnVis( $(this).attr('data-column'), false );
} );
});
But I continue looking for the dynamic hiding of columns with all values equal to zero. It will start work for me if I have a function which checks if all values in a column are equals to zero.