Custom regex filter not working

Custom regex filter not working

KeiSenpaiKeiSenpai Posts: 21Questions: 8Answers: 0

Hello All,

I am trying to use regex filtering to only show the exact match. However, it does not seem to be firing the event for the search.
Here is my test case:

https://jsfiddle.net/cutk2r53/6/

I feel like I must be missing something, so I do appreciate any help.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,181Questions: 26Answers: 4,924
    Answer ✓

    Take a look at the browser's console and you will see this error:

    Uncaught ReferenceError: tableAll is not defined

    Your Datatables API is stored in the variable table. See this updated example:
    https://jsfiddle.net/t7nges4h/

    I moved the event handler inside the $(document).ready() function so that it is in the same scope as the table variable. Also chained draw() to perform the search and update the table.

    Kevin

  • KeiSenpaiKeiSenpai Posts: 21Questions: 8Answers: 0
    edited April 2021

    Thank you again Kevin!
    The only thing I notice, is clearing the filter does not show all the results.
    I added this, is this the best way to solve this:

                if (term) { 
                    tableAll.columns(0).search(regex, true, false).draw();
                } else { 
                    tableAll.columns(0).search('', false, false).draw(); 
                }
    
    
  • kthorngrenkthorngren Posts: 21,181Questions: 26Answers: 4,924
    Answer ✓

    Looks like a good solution!

    Kevin

  • KeiSenpaiKeiSenpai Posts: 21Questions: 8Answers: 0

    Thank you Kevin!

This discussion has been closed.