HTML5 data-search attribute not working

HTML5 data-search attribute not working

xanderhxanderh Posts: 8Questions: 2Answers: 0

Hi,

I'm trying to use the HTML5 data-search attribute on a table, and it doesn't seem to be working. I have the newest version of datatables and have successfully used data-order elsewhere on the same website which works correctly.

I have a table with 2 rows, and the following is the contents of the first cells in each row:
<td data-search="10" class=" nowrap center"><i style="color:#CF000F" class="fa fa-circle"></i></td>
<td data-search="0" class=" nowrap center"><i class="fa fa-circle"></i></td>

I then apply table.column(0).search('10'), and can see this has correctly applied by running table.column(0).search() and having "10" returned to me. When I then call table.draw(), I get no data.

Even if I try using the filter for every cell, searching 10 returns no results.

What could I be doing wrong?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited October 2017 Answer ✓

    I built a test case for you with your two rows and searches. Copied the two column 0 values directly from the above code.. Looks like it works:
    http://live.datatables.net/reruqeha/1/edit

    I get one row returned. Here is the code:

    $(document).ready( function () {
      var table = $('#example').DataTable();
      table.column(0).search('10');
      console.log(table.column(0).search());
      table.draw();
    } );
    

    Maybe you can update the test case to show the problem you are having.

    Kevin

  • xanderhxanderh Posts: 8Questions: 2Answers: 0

    Thanks a lot Kevin :)

    I pasted in my table and datatables initialisation into that and found it stopped working, so removed things until it did. Turns out my columns initialisation option was bad as I was incorrectly using columns.data for a simple identifier of the column, when I probably should have been using columns.name.

    Thanks again!

This discussion has been closed.