Make search functionality only search "begins with"

Make search functionality only search "begins with"

dustinverdindustinverdin Posts: 1Questions: 0Answers: 0
edited February 2010 in General
I am doing some maintenance on an existing datatables installation, and the client wants to make the search functionality do a "begins with" search, not the "contains" functionality as implemented. I know this probably is a regex change in the .js, but before I go tinkering, I wanted to ask on here if someone had a quick answer or fix.

Thanks in advance!

- Dustin

Replies

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Hi Dustin,

    I've got to confess that customising the default filtering in DataTables is one of my 'bugbears'. You can use this example to play around with regex in DataTables: http://datatables.net/examples/api/regex.html . Although the defaulting is good, it's not so great for exactly what you are looking for. This comes about because DataTables will split up the search term into individual words and then try to match on that - so this regular expression can interfere with your own. Even more difficult is that fact that DataTables does the filter on a concatenation of all strings in the row - to make things faster. So you could only search for something at the start in the first column. The way around this is to use custom filtering: http://datatables.net/development/filtering .

    So it is possible, but I think this area needs tidying up in future versions of DataTables...

    Regards,
    Allan
This discussion has been closed.