SoluableNonagon
SoluableNonagon

Reputation: 11755

Why won't DataTable redraw after manual search

I have a table which I would like to search manually. After looking at the API, I see that I can just do:

table.search(somestring).draw();

and this should search the table and redraw it, or so I assume.

$(document).ready(function(){

  var table = $('table').DataTable({
    searching: false,
    paging: false,
    info: false
  }); 

  // add a bunch of rows
  for(var i=0; i<20; i++){
      table.row.add([
      "test "+i, "best "+i, "rest "+i
    ]);
  }

  // draw the table
  table.draw();

  // why won't table redraw with only rows containing 15?
  table.search('15').draw(); 

  // this doesn't work either
  /*
  $('input').on( 'keyup click', function () {
        filterColumn( 1 ); // filter only first column
    } );
  */
});

function filterColumn ( i ) {
  console.log( $('input').val() );
  $('table').DataTable().column( i ).search(
      $('input').val()
  ).draw();  
}

HTML:

<input>

<table>
  <thead>
    <tr>
      <th>column 1</th>
      <th>column 2</th>
      <th>column 3</th>
    </tr>
  </thead>
  <tbody>

  </tbody>
</table>

Plunker: http://plnkr.co/edit/BlwWWw7mlpde4vKqoX2q?p=preview

Upvotes: 0

Views: 1009

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58880

You have searching functionality disabled with searching: false, see searching option for more details.

You need to enable searching with searching: true or by removing this option in order for search() method to work.

If you just want to hide filtering control, use dom: 'lrtip', see dom option for more details.

Upvotes: 1

Related Questions