Click here to Skip to main content
15,906,558 members
Articles / Web Development / HTML
Article

HTML Table Filter ala Excel

Rate me:
Please Sign up or sign in to vote.
4.75/5 (37 votes)
3 Aug 2005CPOL1 min read 224.5K   2.3K   56   71
A way to filter a large table in a simple manner.

Demo

<script language="javascript"></script>

<input id="chk" önclick="enableFilter();" type="checkbox" name="chk" />Enable Filter

Col1Col2
1string
1string2
2String
2STRING2
3
1string
1string2
2String
2STRING2
3

Introduction

When I was writing a web application, I needed a way to filter a large table in a simple manner. The users of the application are used to the auto filtering in MS Excel, so I wanted my filter to have the same look and feel.

Features

  • Once a column is filtered, the dropdown boxes for the rest of the columns are adapted to the changes. Just like the auto filter in Excel works!
  • If a row has the class noFilter, the row will not be touched by the filter.

Using the code

Using the code is very simple. Just include the script to the page:

HTML
<script language="javascript" src="tablefilter.js"></script>

And activate the filter in the OnLoad:

HTML
<body onload="attachFilter(document.getElementById('tbl'), 1)">

attachFilter expects two parameters:

  1. The table object to attach the filter to.
  2. The row number at which the filter row should be inserted.

Browser Compatibility

The script was initially written for IE. I did test it successfully on Firefox, but I do not know if the script works for Netscape browsers.

History

  • 2005/07/27: First version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat Work! Pin
Prasad Khandekar4-Aug-05 1:22
professionalPrasad Khandekar4-Aug-05 1:22 
GeneralGreat Job Pin
Populate1232-Aug-05 23:10
Populate1232-Aug-05 23:10 
GeneralPretty Cool Pin
jairajsun29-Jul-05 12:22
jairajsun29-Jul-05 12:22 
GeneralRe: Pretty Cool Pin
WoutL30-Jul-05 9:52
WoutL30-Jul-05 9:52 
GeneralI haven't actually looked at the code yet, but... Pin
Ashaman29-Jul-05 3:01
Ashaman29-Jul-05 3:01 
QuestionSample? Demo project? Pin
fwsouthern28-Jul-05 5:03
fwsouthern28-Jul-05 5:03 
AnswerRe: Sample? Demo project? Pin
WoutL28-Jul-05 7:43
WoutL28-Jul-05 7:43 
GeneralRe: Sample? Demo project? Pin
Dan F28-Jul-05 13:48
Dan F28-Jul-05 13:48 
You might consider pointing that out in bold characters in the article. I missed it completely, just assumed that that was a screenshot up there at the top of the article.

Very very spiffy idea!
GeneralRe: Sample? Demo project? Pin
fwsouthern28-Jul-05 15:21
fwsouthern28-Jul-05 15:21 
GeneralRe: Sample? Demo project? Pin
WoutL28-Jul-05 23:49
WoutL28-Jul-05 23:49 
GeneralNot to beat a dead horse but ..... Pin
fwsouthern29-Jul-05 4:52
fwsouthern29-Jul-05 4:52 
GeneralRe: Not to beat a dead horse but ..... Pin
WoutL29-Jul-05 5:05
WoutL29-Jul-05 5:05 
GeneralRe: Not to beat a dead horse but ..... Pin
pjreid3-Aug-05 4:11
pjreid3-Aug-05 4:11 
GeneralRight, I just love using "view source" Pin
fwsouthern3-Aug-05 15:07
fwsouthern3-Aug-05 15:07 
GeneralRe: Right, I just love using &quot;view source&quot; Pin
gratou27-Mar-06 10:32
gratou27-Mar-06 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.