Click here to Skip to main content
12,697,545 members (27,858 online)
Click here to Skip to main content
Add your own
alternative version


55 bookmarked

HTML Table Filter ala Excel

, 3 Aug 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
A way to filter a large table in a simple manner.


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

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



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.


  • 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:

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

And activate the filter in the OnLoad:

<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.


  • 2005/07/27: First version.


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


About the Author

Web Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralFilter returns the whole code plus value. Pin
chunchuyo8-Jul-10 6:26
memberchunchuyo8-Jul-10 6:26 
Generaltablefilter and paging Pin
braveheart0131-May-10 2:28
memberbraveheart0131-May-10 2:28 
GeneralRe: tablefilter and paging Pin
WoutL31-May-10 2:51
memberWoutL31-May-10 2:51 
QuestionHello ! Pin
ehuddrey11-Nov-09 11:19
memberehuddrey11-Nov-09 11:19 
AnswerRe: Hello ! Pin
WoutL11-Nov-09 21:47
memberWoutL11-Nov-09 21:47 
QuestionCan the dropdown filter be restricted to a single column? Pin
klsblues1-Jul-09 5:20
memberklsblues1-Jul-09 5:20 
AnswerRe: Can the dropdown filter be restricted to a single column? Pin
WoutL12-Jul-09 23:11
memberWoutL12-Jul-09 23:11 
GeneralRe: Can the dropdown filter be restricted to a single column? Pin
Member 1247297620-Apr-16 4:57
memberMember 1247297620-Apr-16 4:57 
QuestionHow to make the filtering work for the dropdown list column Pin
vijay_kumar16-Dec-08 1:32
membervijay_kumar16-Dec-08 1:32 
AnswerRe: How to make the filtering work for the dropdown list column Pin
WoutL16-Dec-08 2:12
memberWoutL16-Dec-08 2:12 
Generalupdated JS for CUSTOM Filtering Pin
Dhruv P Patel7-May-08 6:56
memberDhruv P Patel7-May-08 6:56 
GeneralRe: updated JS for CUSTOM Filtering (More Info) Pin
Dhruv P Patel7-May-08 6:59
memberDhruv P Patel7-May-08 6:59 
Generalupdated JS for table filtering with CUSTOM Pin
Dhruv P Patel7-May-08 6:53
memberDhruv P Patel7-May-08 6:53 
Generalnew feature Pin
Dhruv P Patel6-May-08 22:05
memberDhruv P Patel6-May-08 22:05 
GeneralRe: new feature Pin
WoutL6-May-08 22:20
memberWoutL6-May-08 22:20 
QuestionNewbie Help Pin
hgee5-Nov-07 9:54
memberhgee5-Nov-07 9:54 
AnswerRe: Newbie Help Pin
WoutL6-Nov-07 0:18
memberWoutL6-Nov-07 0:18 
Generalnice code, but could it do this... :) Pin
andrewmeda6231-Aug-07 12:33
memberandrewmeda6231-Aug-07 12:33 
GeneralRe: nice code, but could it do this... :) Pin
WoutL1-Aug-07 21:12
memberWoutL1-Aug-07 21:12 
GeneralStill Working Great. Pin
belesland19-Jul-07 3:34
memberbelesland19-Jul-07 3:34 
QuestionTable size not changing? Pin
arniedows16-May-07 21:46
memberarniedows16-May-07 21:46 
AnswerRe: Table size not changing? Pin
WoutL16-May-07 22:56
memberWoutL16-May-07 22:56 
Questionhyperlinks Pin
arizen15-Jan-07 2:14
memberarizen15-Jan-07 2:14 
AnswerRe: hyperlinks Pin
WoutL15-Jan-07 2:26
memberWoutL15-Jan-07 2:26 
QuestionRe: hyperlinks Pin
arizen15-Jan-07 2:37
memberarizen15-Jan-07 2:37 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 3 Aug 2005
Article Copyright 2005 by WoutL
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid