Individual column searching (text inputs) --> No matching records found

Individual column searching (text inputs) --> No matching records found

marcel96marcel96 Posts: 4Questions: 2Answers: 1
edited May 2017 in Free community support

Hey,
I am new to DataTables and I have a problem with adding individual column searching via text inputs.
I found some similar posts about this topic but none met my needs.

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#results tfoot th').each( function () {
        var title = $('#results thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );
 
    // DataTable
    var table = $('#results').DataTable();
 
    // Apply the search
    table.columns().every( function () {
        var that = this;
 
        $( 'input', this.footer() ).on( 'keyup change', function () {
            that
                .search( this.value )
                .draw();
        } );
    } );
} );

Basically this is my code. My table has the id=results. The inputs are also initialized and shown.
But when I add some words, every time "No matching records found" is shown as a result of my search.

Why?

When i use global search, its working. But not as a column search...

EDIT: Code is from tutorial here https://datatables.net/examples/api/multi_filter.html

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    You have not copied the example correctly. A line is missing:

    if ( that.search() !== this.value ) {
    
  • marcel96marcel96 Posts: 4Questions: 2Answers: 1

    Oh, sorry. Thanks! How did that happen?

    Nvm, it is still not working...

  • marcel96marcel96 Posts: 4Questions: 2Answers: 1
    Answer ✓

    I found the problem: It didn't work because i have a column, that is not shown in the table and I didn't add the <th>-Tag in the foot.

This discussion has been closed.