Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda