jquery
You can also use this packed version of the scripts. These plugins will then need to be referenced in the section of your page.
<script type="text/javascript" src="Scripts/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="Scripts/jquery.cookie.js"></script> <script type="text/javascript" src="Scripts/picnet.jquery.tablefilter.js"></script>
Or (For Production Code)
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript" src="Scripts/scripts-pack.js"></script>
This plugin will then create the filters in a row in the THEAD element of the table so add this if it is not already there.
<table id='demotable'> <thead> <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr> </thead> <tbody> <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr> .... </tbody> </table>
Hook in your table when the document is loaded.
$(document).ready(function() { $('#demotable).tableFilter(); });
Currently the picnet.jquery.tablefilter.js only supports two kinds of filters. The first and default is ‘text’ which just produces a text box for context sensitive text matches. The second is ‘ddl’, this produces a drop down list that allows the selection of a single item in that list. To specify the filter type simply add “filter-type=‘ddl’” in the header cell of the required column. I.e.
<table id='demotable'> <thead> <tr><th>Col1</th><th>Col2</th><th filter-type='ddl'>Col3</th></tr> </thead> <tbody> <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr> .... </tbody> </table>
We can also pass an options object to control some basic behaviours of the tableFilter. The current supported options are.
Lets suppose that appart from having column filters we also want to have a quick find style filter that matches any cell in a row. To do this simply add the textbox to the additionalFilterTriggers array. TODO
<head> ... <script type="text/javascript"> $(document).ready(function() { // Initialise Plugin var options = { additionalFilterTriggers: [$('#quickfind')] }; $('#demotable).tableFilter(options); }); </script> </head> <body> Quick Find: <input type="text" id="quickfind"/> <table id='demotable'> <thead> <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr> </thead> <tbody> <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr> ... </tbody> </table> ...
Let’s suppose that we have a Boolean column that we want to filter. The best way to do this will be to add a checkbox filter so let’s do this. We will keep the quick find filter to show how to have multiple additional filters.
<head> ... <script type="text/javascript"> $(document).ready(function() { // Initialise Plugin var options = { additionalFilterTriggers: [$('#onlyyes'), $('#quickfind')], matchingRow: function(state, tr, textTokens) { if (!state || state.id != 'onlyyes') { return true; } return state.value != true || tr.children('td:eq(2)').text() == 'yes'; } }; $('#demotable').tableFilter(options); }); < p> </script> </head> <body> Only Show Yes: <input type="checkbox" id="onlyyes"/> <br/> Quick Find: <input type="text" id="quickfind"/> <table id='demotable'> <thead> <tr><th>Col1</th><th>Col2</th><th>Boolean Col3</th></tr> </thead> <tbody> <tr><td>Value 1</th><th>Value 2</th><th>yes</th></tr> ... </tbody> </table> ...
Having a clear filters button comes in very handy, especially when you have a table with a larger number of columns. To add this functionality simply add your clickable control to the clearFiltersControls array.
<head> ... <script type="text/javascript"> $(document).ready(function() { // Initialise Plugin var options = { clearFiltersControls: [$('#cleanfilters')], }; $('#demotable').tableFilter(options); }); </script> </head> <body> <a id="cleanfilters" href="#">Clear Filters</a> <br/> <table id='demotable'> <thead> <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr> </thead> <tbody> <tr><td>Value 1</th><th>Value 2</th><th>Value 3</th></tr> ... </tbody> </table> ...
Guido Tapia, Software Development Manager