Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
How to hide all columns from a table where values are equal to 0?

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!