Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda