Friday, August 10, 2007

Dynamic table search/filter using a single input

I've seen a lot of tables with column filters - each column has a filter. This is the Excel Model. My buddy Travis asked me if I had ever seen it done with one search box - the iTunes Model. Well, I haven't, and some time spent searching around didn't turn up anything. Honestly, I didn't search that hard, because I wanted to build it myself.

Here is the end product. Note, I have only tested this in Firefox and Safari. Update: tested in IE.

So, how do you build it?

First, the behavior:

  • The table to be searched has an arbitrary number of columns.

  • There is one text box for searching

  • Searching is dynamic - start typing and it starts filtering

  • When you search, each word you search for has to appear in at least one column in a row, or that row is hidden

  • All the words you search for don't have to appear in each column.



It's late, so I'll leave the rest of the details for now.

7 comments:

said...

Works great, except it doesn't search th tags.

I have a table like this:

thead
some th's
/thead
tbody
th scope=row
some td's
/tbody

If I turn the th scope=row into td's it works great. I assume you exclude th tags so it doesn't filter the header, but what about using the thead thead tag instead?

said...

This was really helpful, had to use it to filter a table of chemicals.

said...
This post has been removed by the author.
said...

I really like your concept with this. I am hoping to use it in an intranet app. I lifted the js and the init stmt directly from your demo....however I find that in both IE and FF not all char's result in a filter. 1-9, j, k, q, v, x, y & z work fine, but no other alphas will initiate a filter. Same result for uc and lc. I note in your example this problem doesnt exist. Any thoughts?

said...

perfect- exactly what i needed for a company intranet page. saved me the time of writing it myself - kudos!

said...

You saved my life with this.
Just so you know than i'm not an idiot or an ass-hole, i'm not pretending i wrote that from scratch :)
sorry bout my bad english.


Greetings from paraguay

said...

awesome script. ridiculously helpful when I needed to make a filter for a company project in Livelink.