Click here to Skip to main content
Click here to Skip to main content

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

Col1 Col2
1 string
1 string2
2 String
1 string
1 string2
2 String


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

Comments and Discussions

GeneralFilter returns the whole code plus value. Pinmemberchunchuyo8-Jul-10 6:26 
Generaltablefilter and paging Pinmemberbraveheart0131-May-10 2:28 
GeneralRe: tablefilter and paging PinmemberWoutL31-May-10 2:51 
QuestionHello ! Pinmemberehuddrey11-Nov-09 11:19 
AnswerRe: Hello ! PinmemberWoutL11-Nov-09 21:47 
QuestionCan the dropdown filter be restricted to a single column? Pinmemberklsblues1-Jul-09 5:20 
AnswerRe: Can the dropdown filter be restricted to a single column? PinmemberWoutL12-Jul-09 23:11 
QuestionHow to make the filtering work for the dropdown list column Pinmembervijay_kumar16-Dec-08 1:32 
AnswerRe: How to make the filtering work for the dropdown list column PinmemberWoutL16-Dec-08 2:12 
Generalupdated JS for CUSTOM Filtering PinmemberDhruv P Patel7-May-08 6:56 
GeneralRe: updated JS for CUSTOM Filtering (More Info) PinmemberDhruv P Patel7-May-08 6:59 
Generalupdated JS for table filtering with CUSTOM PinmemberDhruv P Patel7-May-08 6:53 
Generalnew feature PinmemberDhruv P Patel6-May-08 22:05 
GeneralRe: new feature PinmemberWoutL6-May-08 22:20 
QuestionNewbie Help Pinmemberhgee5-Nov-07 9:54 
AnswerRe: Newbie Help PinmemberWoutL6-Nov-07 0:18 
Generalnice code, but could it do this... :) Pinmemberandrewmeda6231-Aug-07 12:33 
GeneralRe: nice code, but could it do this... :) PinmemberWoutL1-Aug-07 21:12 
GeneralStill Working Great. Pinmemberbelesland19-Jul-07 3:34 
QuestionTable size not changing? Pinmemberarniedows16-May-07 21:46 
AnswerRe: Table size not changing? PinmemberWoutL16-May-07 22:56 
Questionhyperlinks Pinmemberarizen15-Jan-07 2:14 
AnswerRe: hyperlinks PinmemberWoutL15-Jan-07 2:26 
QuestionRe: hyperlinks Pinmemberarizen15-Jan-07 2:37 
AnswerRe: hyperlinks PinmemberWoutL15-Jan-07 3:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.141216.1 | Last Updated 3 Aug 2005
Article Copyright 2005 by WoutL
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid