Click here to Skip to main content
15,905,229 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

 
AnswerRe: hyperlinks Pin
WoutL15-Jan-07 2:08
WoutL15-Jan-07 2:08 
AnswerRe: hyperlinks Pin
arizen15-Jan-07 2:12
arizen15-Jan-07 2:12 
QuestionOne filter for 3 columns: it´s possible? Pin
OdaScatolini12-Jan-07 5:33
OdaScatolini12-Jan-07 5:33 
AnswerRe: One filter for 3 columns: it´s possible? Pin
WoutL14-Jan-07 21:00
WoutL14-Jan-07 21:00 
GeneralRe: One filter for 3 columns: it´s possible? Pin
OdaScatolini15-Jan-07 5:00
OdaScatolini15-Jan-07 5:00 
Generalhelp please! Pin
OdaScatolini10-Jan-07 7:24
OdaScatolini10-Jan-07 7:24 
GeneralRe: help please! Pin
WoutL10-Jan-07 20:37
WoutL10-Jan-07 20:37 
Questionno filter for one column Pin
devzo31-Oct-06 1:28
devzo31-Oct-06 1:28 
AnswerRe: no filter for one column Pin
WoutL31-Oct-06 21:01
WoutL31-Oct-06 21:01 
AnswerRe: no filter for one column Pin
dribagnac22-Jan-07 2:23
dribagnac22-Jan-07 2:23 
AnswerRe: no filter for one column Pin
dribagnac22-Jan-07 2:33
dribagnac22-Jan-07 2:33 
GeneralNew Features Pin
justinkelly23-Jul-06 20:30
justinkelly23-Jul-06 20:30 
GeneralChanging the font/color of the cell Pin
ahooja28-Jun-06 11:40
ahooja28-Jun-06 11:40 
GeneralRe: Changing the font/color of the cell Pin
WoutL28-Jun-06 20:55
WoutL28-Jun-06 20:55 
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 
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 

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.