Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!