How to search for exact value in header search box

How to search for exact value in header search box

martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

live.datatables.net/mowobugu/1/edit

I cant figgur out how to search for the exact value in the added header search code in above example.. Is there a way to make datatables search for the exact result? Atm when searching Anneke, the result is also showing Janneke. It should only show Anneke.

Answers

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

    Use regex searching. See this example. The select input example uses regex searching. Change your search to use regex similar to the select example.

    Also you might want to use orderCellsTop to move the sorting events to the top row.

    Kevin

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    Thanks for reacting. I did found examples like yours. But I dont understand how to implent the regex into the example in my link.. Please help

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    See below example. It is just not working for me all the options I find. So please help how to make this work..

    live.datatables.net/mowobugu/1/edit

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    When changing this.value to this.val it seems to work but than when empty it does nog reset..

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

    Your first example has this error:

    VM448:41 Uncaught TypeError: $(...).value is not a function

    You have this:

    .search("^" + $(this).value() + "$", true, false, true)
    

    Use $(this).val() instead of $(this).value(). Here is the updated example:
    http://live.datatables.net/mowobugu/3/edit

    Kevin

  • martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

    Thanks. I noticed that as i posted in my first comment. But when removing the results the table is not
    refreshed to the original results. Any way to do this?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It just needs some logic to determine if there is a search string in place - see updated example here: http://live.datatables.net/mowobugu/4/edit

    Colin

Sign In or Register to comment.