We help IT Professionals succeed at work.
Get Started

JQuery Search Filter

Ridgejp
Ridgejp asked
on
387 Views
Last Modified: 2017-03-15
Hi,

I'm currently using a JQuery Search filter that up until now has performed brilliantly ... but I'd like to tweak it to handle 'character spaces' in the search terms.

The query looks like this currently: -

<script> 
    $(document).ready(function () {
		(function ($) 
		{
			$('#filter').keyup(function () {
            var rex = new RegExp($(this).val(), 'i');
            $('.searchable tr').hide();
            
            $('.searchable tr').filter(function () {
                return rex.test($(this).text());
            }).show();

            })

            }(jQuery));
    });
</script>

Open in new window


The search function fails if I search a record set returned into a bootstrap table using mysql as it will only find results where there is no character spacing. So if a product code is present in the returned record set such as "WHITE OVERSHOES" (by way of example) I would have to search for "WHITE"  or "OVERSHOES" as it would not be able to find "WHITE OVERSHOES" on account of the space.

How do I change this?

J
Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE