How to filter ?

How to filter ?

andras2andras2 Posts: 31Questions: 12Answers: 0
edited April 2022 in DataTables

Hi there,

I would like to ask how to filter Datatbles, I have found the example;
https://datatables.net/examples/api/regex.html

and used the code below to search column No.2 for "New project2", but it did not work.

$('#example').DataTable().column( 2 ).search("New project2",True,True).draw();

I would like to filter the table by the given project name.

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    One problem might be True. Javascript uses true not True. If this doesn't help then post a link to your page or a test case replicating the problem.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • andras2andras2 Posts: 31Questions: 12Answers: 0
    edited April 2022

    Thank you, It evenatualy worked, but I had to use List inside column.

    $('#example').DataTable().column( [2] ).search("New project2",True,True).draw();

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    That doesn't sound right. IIRC you are using Python. Booleans in Python begin with uppercase, like True. However booleans in Javascript are all lower case, like true. This messes me up too. You should be getting a console log error when trying to use True.

    Kevin

  • andras2andras2 Posts: 31Questions: 12Answers: 0

    Sorry, yes the right line is in normal, non-capital true;

    $('#example').DataTable().column( [2] ).search("New project2",true,true).draw();

  • andras2andras2 Posts: 31Questions: 12Answers: 0

    I also noticed that I want to search "New project" the result is including other records that includes the search word. I also get "New project2" or New project1" too.

    How can I make search strict to find exactly search words only?

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited April 2022

    Use.a regex expression, something like this:

    $('#example').DataTable().column( [2] ).search("^New project$",true,false).draw();
    

    Also you will want to set the 3rd parameter to false to turn off Smart Search. See the search() docs for details.

    Kevin

Sign In or Register to comment.