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

320
Visualizações
Unable to expand child rows when dynamically creating multiple DataTables

I am using the DataTables plugin to dynamically create tables with expandable child rows. A vars object contains all of the generated tables. The problem I'm having is that the tables child rows only expand for the last table that is generated. When trying to expand the child rows for the previous tables, nothing happens.

var row = x.row(tr); only returns a row when expanding a child row for last table that is generated. For the previous tables that are generated it returns an empty array and the child rows do not expand.

Code for generating tables:

vars = {};

for (var i = 0; i < shapes.length; i++) {

            var shapeType = shapes[i].points.length == 1 ? "Point" : "Line";

            document.getElementById("addCoordsScreen").innerHTML += '<div class="coordTableHeader">Shape(' + shapeType + '):</div><table id="coordinateTable' + i + '" class="display" style="width: 100%"></table><br/>';

            window.vars['tableName' + i] = $("#coordinateTable" + i).DataTable({
                data: dataSet,
                ordering: false,
                paging: false,
                searching: false,
                bInfo: false,
                columns: [
                    {
                        render: function (data, type, row) {
                            return "<span title='Add coordinates' class='fa fa-plus plusSymbol')'/>";
                        }
                    },
                    { title: "COLUMN1" },
                    { title: "COLUMN2" },
                    {
                        render: function (data, type, row) {
                            return "<span id='" + data[3] + "' class='fa fa-window-close fa-lg removeEN')'/>";
                        }
                    }
                ]
            }).draw();
        }

Code for expanding child rows:

$(document).on('click', ".plusSymbol", function () {
        $(this).closest('tr').find("span").toggleClass('fa-plus fa-minus');


        var tr = $(this).closest('tr');
        var tableId = $(this).closest('table').attr('id');
        tableId = tableId.split("coordinateTable")[1];
        var x = vars['tableName' + tableId];
        var row = x.row(tr);

        if (row.child.isShown()) {
            row.child.hide();
        }
        else {
            row.child(getChildRow(row.data())).show();
        }
    });
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