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

206
Visualizações
How can I search (and filter out) data inside a nested table with datatables?

I am working with a table that has two rows: the header row and then the body row. In the body row, each column contains another table. Like this:

<table id="example">
    <thead>
        <tr>
            <td>Col A</td>
            <td>Col B</td>
            <td>Col C</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td valign="top">
                <table>
                    <tr>
                        <td>Data</td>
                        <td>Data2</td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <table>
                    <tr>
                        <td>Data3</td>
                        <td>Data4</td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <table>
                    <tr>
                        <td>Data5</td>
                        <td>Data6</td>
                    </tr>
                </table>
            </td>
        </tr>
    </tbody>
</table>

I have my datatable setup like this:

<script type="text/javascript">

    const columns = [
      { title: '' },
    ]

    let table = $('#example').DataTable({
      createdRow: function(row) {
        $(row).find('td table')
          .DataTable({
            columns: columns,
            dom: 'tf'
          })
      }
    })
</script>

The problem is that when I search for something, I want ALL the tables (including the nested ones) to filter out the results. So in my code above, as an example, if I search for "Data2", I would expect the second and third columns to become empty and just one result appear in the first column. However, at present, since "Data2" is found in this row (of which there is only one in this table), it simply returns ALL the data.

I found a REALLY good example that is close to what I want (which I what my current code is based on):

http://jsfiddle.net/davidkonrad/8pzkr6yn/

If we use the example from the JSFiddle, you can see searching for "722" returns only the last row, but still all the results from each nested table from within that row are there. I'd like it so that searching 722 globally will return the results as if 722 was searched individually in each column.

How can I adjust the code to make it so that all the nested tables get filtered out, not just the main table?

Bonus points if we can eliminate the search box in every nested datatable!

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