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

114
Visualizações
Filtering DataTable.js rows by data-attribute

I am working on a data table using DataTable.js and need to create filtering to limit a row based on a data-attribute. I have an attribute of data-active set on the <tr>. Currently in my testing I have 6 rows, 2 inactive and 4 active - like so.

<tr class="funder funder--inactive" data-active="false">...1...</tr>
<tr class="funder funder--active" data-active="true">...2...</tr>
<tr class="funder funder--active" data-active="true">...3...</tr>
<tr class="funder funder--active" data-active="true">...4...</tr>
<tr class="funder funder--inactive" data-active="false">...5...</tr>
<tr class="funder funder--active" data-active="true">...6...</tr>

Then in the DataTable search, I added a function to hide any row based on the data-active attribute.

$.fn.dataTable.ext.search.push(function(settings, data, dataIndex, rowObj, counter) {
    var el = settings.aoData[counter].nTr,
        isActive = $(el).data('active');

    return isActive;
});

And lastly I build the table using DataTable.js

var $fundersTable = $('#fundersList').DataTable({ ... });

The table is then filtered down to 4 rows, but instead of being the rows with data-active="true" it only filters the first 2 rows - leaving the following rows.

<tr class="funder funder--active" data-active="true">...3...</tr>
<tr class="funder funder--active" data-active="true">...4...</tr>
<tr class="funder funder--inactive" data-active="false">...5...</tr>
<tr class="funder funder--active" data-active="true">...6...</tr>

Is there something I'm missing on specifying the row index on which item to limit? All the example in their docs seem to just return true or false per row as I've done here.

Any help is greatly appreciated, thanks!

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