hide columns dinamic if the data row is specitic

hide columns dinamic if the data row is specitic

ThomasFerrazThomasFerraz Posts: 7Questions: 3Answers: 0

Hi all, i have a problem with a Datatables.
Normally i hide specific column but now i need a hide a column If the information in the column is specific.
Example: if my column 7 have a information "99" i need hide this column.
I dont find anything google or another forum about this.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    I would look at using filter() to get the data that contains "99" in column 7. If there is a result then hide the column. The first example in the doc page can be modified for your specific rules.

    Kevin

  • ThomasFerrazThomasFerraz Posts: 7Questions: 3Answers: 0

    Kevin, tks.
    But do you have a example of use the filter()?
    I look the documentation but i dont undertand the use after load my datable

    i need used the filter after the ajax load the data to my datatable.

    my code:

    function CarregarGridProgramaGoverno(ProgramaGoverno)
    {
    try {
    var tbGridProgramaGoverno = $("#GridProgramaGoverno");
    var dataObject = ProgramaGoverno;

        if (!$.fn.DataTable.isDataTable("#GridProgramaGoverno")) {
            tbGridProgramaGoverno = tbGridProgramaGoverno.DataTable({
                "lengthMenu": [[5, 10, 25], [5, 10, 25]],
                "autoWidth": false,
                "columns": [
                    { "data": "COD_CORPORATIVO_IPG" },
                    { "data": "TOTAL_PROGRAMA", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) }, //format to number data
                    { "data": "PARCELA_1", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0)},
                    { "data": "PARCELA_2", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0)},
                    { "data": "PARCELA_3", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_4", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_5", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_6", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_7", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_8", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_9", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_10", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_11", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) },
                    { "data": "PARCELA_12", "type": "num-fmt", render: $.fn.dataTable.render.number('.', '.', 0) }
                ],
                "oLanguage": {
                    "sEmptyTable": "Nenhum registro encontrado",
                    "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                    "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                    "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                    "sInfoPostFix": "",
                    "sInfoThousands": ".",
                    "sLengthMenu": "_MENU_ resultados por página",
                    "sLoadingRecords": "Carregando...",
                    "sProcessing": "Processando...",
                    "sZeroRecords": "Nenhum registro encontrado",
                    "sSearch": "Pesquisar",
                    "oPaginate": {
                        "sNext": "Próximo",
                        "sPrevious": "Anterior",
                        "sFirst": "Primeiro",
                        "sLast": "Último"
                    },
                    "oAria": {
                        "sSortAscending": ": Ordenar colunas de forma ascendente",
                        "sSortDescending": ": Ordenar colunas de forma descendente"
                    }
                }
            });
        } else {
            tbGridProgramaGoverno = tbGridProgramaGoverno.DataTable();
        }
    
        //Limpa os dados da grid antes de repopular
        tbGridProgramaGoverno.clear();
        tbGridProgramaGoverno.draw(false);
    
        for (var i = 0; i < ProgramaGoverno.length; i++)
        {
            var pgnto = {
                            "Id": (createGuid() + "-" + [i] + "-" + new Date().getMilliseconds()),
                            "COD_CORPORATIVO_IPG": ProgramaGoverno[i]["COD_CORPORATIVO_IPG"],
                            "TOTAL_PROGRAMA": ProgramaGoverno[i]["TOTAL_PROGRAMA"],
                            "PARCELA_1": ProgramaGoverno[i]["PARCELA_1"], //I Need hide if the data is '0'
                            "PARCELA_2": ProgramaGoverno[i]["PARCELA_2"],//I Need hide if the data is '0'
                            "PARCELA_3": ProgramaGoverno[i]["PARCELA_3"],//I Need hide if the data is '0'
                            "PARCELA_4": ProgramaGoverno[i]["PARCELA_4"],//I Need hide if the data is '0'
                            "PARCELA_5": ProgramaGoverno[i]["PARCELA_5"],//I Need hide if the data is '0'
                            "PARCELA_6": ProgramaGoverno[i]["PARCELA_6"],//I Need hide if the data is '0'
                            "PARCELA_7": ProgramaGoverno[i]["PARCELA_7"],//I Need hide if the data is '0'
                            "PARCELA_8": ProgramaGoverno[i]["PARCELA_8"],//I Need hide if the data is '0'
                            "PARCELA_9": ProgramaGoverno[i]["PARCELA_9"],//I Need hide if the data is '0'
                            "PARCELA_10": ProgramaGoverno[i]["PARCELA_10"],//I Need hide if the data is '0'
                            "PARCELA_11": ProgramaGoverno[i]["PARCELA_11"],//I Need hide if the data is '0'
                            "PARCELA_12": ProgramaGoverno[i]["PARCELA_12"]//I Need hide if the data is '0'
                        };
    
            tbGridProgramaGoverno.row.add(pgnto);
        }
    
        tbGridProgramaGoverno.draw(false);
        tbGridProgramaGoverno.order([[0, 'asc']]);
    
        //bindEventConsultarProgramaGoverno(tbGridProgramaGoverno);
    
        console.log(tbGridProgramaGoverno);
        var htmlBody = "";
    } catch (e) {
        $.unblockUI();
        console.error(e);
    }
    

    }

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Here is an example:
    http://live.datatables.net/nalotira/1/edit

    There are two buttons; One that looks for "Director" (which is in the column) and the other looks for "CEO" (which is not in the column).

    Click the buttons. The column will be hidden if the data is found or shown if not.

    Kevin

  • ThomasFerrazThomasFerraz Posts: 7Questions: 3Answers: 0

    tks man its working now.

This discussion has been closed.