Search filter API

Search filter API

dylanmacdylanmac Posts: 49Questions: 7Answers: 1
edited February 2014 in DataTables 1.10
I'm trying out DT 1.10 beta. It looks great but I am not sure how to construct a multi-column filter with smart filtering turned off. Is it like so?

[code]

$('#table').DataTable().columns( col1Index,col2Index ).search( filterValue1 [[false]], filterValue2 [[false]] ).draw();

[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you want to apply a different search filter to different columns, you need to select the two columns individually.

    [code]
    $('#table').DataTable()
    .column( col1Index ).search( filterValue1, false )
    .column( col2Index ).search( filterValue2, false )
    .draw();
    [/code]

    Allan
  • dylanmacdylanmac Posts: 49Questions: 7Answers: 1
    edited March 2014
    Hi Allan -

    I love the new API. Really excellent work. Thank you. I will have to convince our architect to let us release our app using "beta" software but the proof is in the pudding: I have not encountered any bugs so far.

    So I am trying to add a search reset link for my table but it doesn't seem to be working. It's possible that some of my functions are colliding but there are no console errors. here's how I'm calling it:

    $('#productListTable').DataTable().search('').draw();

    When I pass in an actual value within the quotes it filters just fine. I didn't see anything in the search() API that covers this use case.

    Thank you!
  • jolyon2000jolyon2000 Posts: 12Questions: 0Answers: 0
    Is this search() function supposed to send a server request if server-side processing is activated?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You need to call the `draw()` method. `search()` queue up the search parameter. As it says in the documentation:

    > Please be aware that this method sets the search to apply to the table only - it does not actually perform the search. In order to have the search performed and the result shown, use the draw() method, which can be called simply as a chained method of the search() method's returned object - for example table.search( 'Fred' ).draw();. This is to provide the ability to queue multiple changes before performing a draw.

    Allan
  • dylanmacdylanmac Posts: 49Questions: 7Answers: 1
    edited March 2014
    Allan -

    Was this answer for me or jolyon2000?

    When trying to "reset" the table to display all records I have tried the following:

    $('#productListTable').DataTable().search('').draw(); // empty string
    $('#productListTable').DataTable().draw(); // doesn't work but no JS error either

    Not sure what else to try.

    Dylan
  • dylanmacdylanmac Posts: 49Questions: 7Answers: 1
    Anyone? Anyone know how to reset the search filter? Passing in an empty string ('') does not seem to work.
This discussion has been closed.