Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using jQuery to filter on table cells ...

Posted on 2012-08-24
2
Medium Priority
?
388 Views
Last Modified: 2012-08-25
Hey all.

I have a table and a search field. I want to use jQuery to search the table cells and apply a class to the cell(s) that match the search term, case insensitive and using "matches".

This is what I've got.

$("table tbody tr").find('td:eq(2)').filter(function(e){
            var searchterm = $(this).text().toLowerCase();
            var searchtext = term.toLowerCase();

            $(this).text().toLowerCase() == term.toLowerCase();
            //return searchterm.match('/\b'+searchtext+'/gi');
      }).parent('tr').show().addClass('searchfound');

This code works if I give complete string. Exampe: if cell contains "test one", I have to enter "test one". I want to just enter "test" or just "one" and still get a hit.

Any ideas? That regular expression I would expect to work but to return it is not working.
0
Comment
Question by:Webspeeder
2 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 2000 total points
ID: 38331633
try
      $("table tbody tr").find('td').filter(function(e){
            var searchterm = $(this).text().toLowerCase();
            var searchtext = term.toLowerCase();
            var patt=new RegExp(searchtext,'gi');
            return patt.test(searchterm)
      }).parent('tr').show().addClass('searchfound');
0
 

Author Comment

by:Webspeeder
ID: 38333232
I think that did the trick. Thank you very much.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question