Click here to Skip to main content
15,918,303 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 225K   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

 
GeneralEnable/Disable filter question Pin
ahooja27-Jun-06 7:03
ahooja27-Jun-06 7:03 
GeneralRe: Enable/Disable filter question Pin
WoutL27-Jun-06 20:37
WoutL27-Jun-06 20:37 
GeneralRe: Enable/Disable filter question Pin
dribagnac22-Jan-07 2:21
dribagnac22-Jan-07 2:21 
GeneralRealmente bueno el código.... Pin
Juan Melgar20-Apr-06 14:52
Juan Melgar20-Apr-06 14:52 
GeneralQuick question Pin
pcockey15-Feb-06 13:58
pcockey15-Feb-06 13:58 
GeneralRe: Quick question Pin
WoutL16-Feb-06 0:15
WoutL16-Feb-06 0:15 
GeneralRe: Quick question Pin
pcockey16-Feb-06 10:08
pcockey16-Feb-06 10:08 
GeneralGreat Job Pin
henk jansen11-Oct-05 3:27
henk jansen11-Oct-05 3:27 
This is a truly nice peace of code. As mentioned earlier i think it would be a valuable addition if one could select the row(s) to filter from.


GeneralRe: Great Job Pin
WoutL11-Oct-05 3:34
WoutL11-Oct-05 3:34 
QuestionAdditional Function Pin
klmohr7-Oct-05 15:21
klmohr7-Oct-05 15:21 
AnswerRe: Additional Function Pin
WoutL11-Oct-05 21:08
WoutL11-Oct-05 21:08 
GeneralRe: Additional Function Pin
klmohr12-Oct-05 15:15
klmohr12-Oct-05 15:15 
GeneralSome Html/css resources. Pin
Anonymous14-Aug-05 2:56
Anonymous14-Aug-05 2:56 
GeneralNice! Works for Opera 8.02! Pin
Denis Chekhlov11-Aug-05 23:50
Denis Chekhlov11-Aug-05 23:50 
GeneralFirefox extension... Pin
Oskar Austegard11-Aug-05 2:58
Oskar Austegard11-Aug-05 2:58 
GeneralReally good Pin
ieaeitsch5-Aug-05 5:34
ieaeitsch5-Aug-05 5:34 
GeneralExactly what I have spent hours looking for Pin
edhenry303244-Aug-05 5:20
edhenry303244-Aug-05 5:20 
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 

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.