Live searching/filtering for HTML tables in a jQuery plugin

Overview

jQuery Filter Table Plugin

This plugin will add a search filter to tables. When typing in the filter, any rows that do not contain the filter will be hidden.

One can also define clickable shortcuts for commonly used terms.

See the demos at http://sunnywalker.github.com/jQuery.FilterTable

Usage

Include the dependencies:

<script src="/path/to/jquery.js"></script>
<script src="/path/to/bindWithDelay.js"></script> <!-- optional -->
<script src="/path/to/jquery.filtertable.js"></script>
<style>
.filter-table .quick { margin-left: 0.5em; font-size: 0.8em; text-decoration: none; }
.fitler-table .quick:hover { text-decoration: underline; }
td.alt { background-color: #ffc; background-color: rgba(255, 255, 0, 0.2); }
</style> <!-- or put the styling in your stylesheet -->

Then apply filterTable() to your table(s):

<script>
$('table').filterTable(); //if this code appears after your tables; otherwise, include it in your document.ready() code.
</script>

Problems?

Be sure to check the FAQ file for common issues if the plugin does not seem to be working as intended.

Note that the plugin does not work as expected when using cells with rowspan.

Options

Option Type Default Description
autofocus boolean false Makes the filter input field autofocused (not recommended for accessibility reasons)
callback function(term, table) null Callback function after a filter is performed. Parameters:
  • term filter term (string)
  • table table being filtered (jQuery object)
containerClass string filter-table Class applied to the main filter input container
containerTag string p Tag name of the main filter input container
hideTFootOnFilter boolean false Controls whether the table's tfoot(s) will be hidden when the table is filtered
highlightClass string alt Class applied to cells containing the filter term
ignoreClass string '' Ignore any cells with this class when filtering
ignoreColumns array [] Ignore these columns (0-indexed) when filtering
inputSelector string null Use this selector to find the filter input instead of creating a new one (only works if selector returns a single element)
inputName string filter-table Name attribute of the filter input field
inputType string search Tag name of the filter input itself
label string Filter: Text to precede the filter input
minChars integer 1 Filter only when at least this number of characters are in the filter input field
minRows integer 8 Only show the filter on tables with this number of rows or more
placeholder string search this table HTML5 placeholder text for the filter input
preventReturnKey boolean true Trap the return key in the filter input field to prevent form submission
quickList array [] List of clickable phrases to quick fill the search
quickListClass string quick Class of each quick list item
quickListClear string '' Label for the clear filtering quick list item (or none if blank)
quickListGroupTag string '' Tag name surrounding quick list items (e.g., ul)
quickListTag string a Tag name of each quick list item (e.g., a or li)
visibleClass string visible Class applied to visible rows

Styling

Suggested styling:

.filter-table .quick { margin-left: 0.5em; font-size: 0.8em; text-decoration: none; }
.fitler-table .quick:hover { text-decoration: underline; }
td.alt { background-color: #ffc; background-color: rgba(255, 255, 0, 0.2); }

There is a caveat on automatic row striping. While alternating rows can be striped with CSS, such as:

tbody td:nth-child(even) { background-color: #f0f8ff; }

Note that CSS cannot differentiate between visible and non-visible rows. To that end, it's better to use jQuery to add and remove a striping class to visible rows by defining a callback function in the options.

$('table').filterTable({
    callback: function(term, table) {
        table.find('tr').removeClass('striped').filter(':visible:even').addClass('striped');
    }
});

Dependencies

Other than jQuery, the plugin will take advantage of Brian Grinstead's bindWithDelay if it is available.

License

(The MIT License)

Copyright (c) 2012 Sunny Walker [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • rewrite to CoffeeScript

    rewrite to CoffeeScript

    Hello there,

    First, thanks for a nice plugin.

    I needed to add the possibility to specify row & cell selectors for your plugin, and on that occasion rewrote it to CoffeeScript, which in my opinion results in a bit cleaner code.

    I also made a slight changes to the generated markup and added few more options.

    If you'd want to merge this into your branch please feel free to go ahead.

    Best wishes, Tomas

    opened by tomasc 5
  • default minRows to 0

    default minRows to 0

    I have just spent an unhealthy amount of time troubleshooting the same problem as in https://github.com/sunnywalker/jQuery.FilterTable/issues/26.

    filterTable did show up for one of our tables but not for the other, with the same code. I read the JS console, tried to run .filterTable() manually in the console, saw that there were no additions to the DOM, checked that the plugin was called at all, read the, in my mind, important introduction in the manual over and over. I did not expect to find a minRows setting that defaults to hiding everything.

    I suspect most users don't like when DOM elements are sometimes there and sometimes not.

    My suggestion is to either default minRows to 0 or to at least add a message with console.log when the table is skipped. What do you think?

    opened by emilv 4
  • FilterTable filters rows of sub tables as well

    FilterTable filters rows of sub tables as well

    Hi there,

    thank you versy much for this nice plugin.

    I just recognized that rows of sub tables within a table cell are filtered as well.

    Is that a purposed behavior?

    opened by WulleBulle 3
  • Key enhancement: Custom filter input option

    Key enhancement: Custom filter input option

    Firstly thanks for writing this plugin. I have been using it since the past week and am very pleased with its performance.

    It would be great to have an option to attach a custom text box as the filter input field. This is very important to place the text box anywhere to suit the design.

    Thanks

    opened by pratikt 2
  • Wrong search results

    Wrong search results

    Playing around with plain simple example gave me wrong search results.

    For example: typing 'tt' gives records where one column ends with a 't' and seconds start with a 't'. It looks like columns in a record are being concatenated into a long string. To clarify the issue another example could be 'polkone'.

    opened by pawellenart 2
  • can't filter on form elements

    can't filter on form elements

    I have used filterTable for quite some time and love it. However, now I have a long table full of textboxes, selects and textareas. Those elements does not seem to be part of the filtering rules.

    Do you have any tips on how to tweak the component to see inside those elements too?

    opened by aquamoth 1
  • bug in samples

    bug in samples

    At least this sample is on an https page failing to load JQuery over http - and failing due to mixed content.

    https://sunnywalker.github.io/jQuery.FilterTable/examples/filtertable-existing-input.html

    opened by aquamoth 1
  • Sorting on table column?

    Sorting on table column?

    Nice script! Is there any chance of adding sorting functionality? I am using it on a pricing table and would love to be able to sort the filtered results by the pricing column.

    Thanks

    opened by GoodLookin 1
  • Option inputSelector missing

    Option inputSelector missing

    The option inputSelector is missing from the source code. The documentation mentions inputSelector but instead, filterSelector is used. Please fix this.

    opened by rajesh1158 1
  • Ability to have custom txt input field

    Ability to have custom txt input field

    I have added code to have an option to attach a custom text box as the filter input field. This is very important to place the text box anywhere to suit the design.

    opened by pratikt 1
  • Optional autofocus the filter table textbox through an option

    Optional autofocus the filter table textbox through an option

    I added a autofocus option (enabled by default) and tested it (in Chrome) in both enabled and disabled. Works pretty well. Also updated the readme to reflect the option.

    opened by penguinpowernz 1
  • no way to skip hiding rows

    no way to skip hiding rows

    I tried ignoreClass but the tr or td I have the associated class applied to are still hidden. This seems like an alternate meaning of "ignoring filtering", I also understand your original reasoning for it now (to skip finding a row/cell). Maybe there could be another option specifically to skip hiding, rather than skip finding?

    opened by nmz787 1
  • [Request] Filter on all Terms with term matching per-row (not per-cell)

    [Request] Filter on all Terms with term matching per-row (not per-cell)

    Hi,

    Thanks to share your work ! I like the two examples "Filter on Any Term" and "Filter on All Terms", very useful !

    I would like to know if there is a way to filter with terms per-row ? For example if you search "James,one-partial" it should display only one line / one row :

    20 | James Abram Garfield | one-partial | 1881

    opened by schmurtzm 0
  • Problems with responsive Design

    Problems with responsive Design

    Seems that filter is not working with responsive design if screen width is lower than around 760px. Is there a solution for this or did I overread something?

    opened by labby 0
  • Using a delay on input field / using bindwithdelay

    Using a delay on input field / using bindwithdelay

    I am currently looking at how to implement a search with delay.

    The point is, I have a list of nearly 20000 entries with 5 columns and need tablewide search. This is very slow, especially when users are beginning to enter their search term. What I want is a certain delay on the input field, to only fire the search event when there is no further entry for x second. I thought, bindwithdelay would solve this, but simply adding it to the page did nothing. Further, I could not find an example for bindwithdelay or documentation on how to use these two together.

    Kind regards

    opened by chross 0
  • Show table header without THEAD - workaround

    Show table header without THEAD - workaround

    As written in the description and the FAQ, the filter looks for TBODY and THEAD.

    If you can't change the HTML source-code and are stuck with simple TR and TD, you can use this dirty workaround to show the first table-line.

    Add the following line: "tbody.find('tr:eq(0)').show().addClass(settings.visibleClass);" around line 240 so it looks like:

    [...] 
    // remove previous highlights
    all_tds.removeClass(settings.highlightClass);
    				
    // dirty workaround
    tbody.find('tr:eq(0)').show().addClass(settings.visibleClass);
    	
    // hide footer if the setting was specified
    if (settings.hideTFootOnFilter) {
    [...]
    

    This is NOT a real issue. We had this problem on an old Sharepoint-installation and I wanted to share our solution. :)

    opened by msteudtn 0
  • Filter table by JS function?

    Filter table by JS function?

    I'd like to build filter phrases outside the application and if some event happens, it should be applied to the table. So i need a way to call the plugin and force it to filter the table by the words supplied, e.g. $('#mytable').filterTable().term("term1,term2");

    opened by igittigitt 0
Releases(v1.5.7)
  • v1.5.7(Mar 22, 2017)

  • 1.5.6(May 24, 2016)

  • 1.5.5(Aug 25, 2015)

    • The filtering should now trigger automatically on input on iOS. For some reason, Safari iOS triggers a blur event on field change but not keyup or other related events.
    • A new feature for extending the plugin (option filterExpression) has been added. The default is unchanged—the literal filter string.
      • To search for any of multiple terms, set filterExpression to filterTableFindAny to perform an OR search which delimits on space or comma characters in the filter field. Thank you to Lukas for the implementation. An example page is included.
      • To search for all of multiple terms, set filterExpression to filterTableFindAll to perform an AND search which delimits on space or comma characters in the filter field. Note that the matching is per-cell not per row, so each cell must have all terms to match. An example page is included.
    • A new feature for ignoring columns is available via the ignoreColumns option. Provide an array of column numbers (0-indexed) to ignore those columns during filtering. The default is no columns are ignored. An example page is included.
    • A new feature for ignoring cells with a specific class is available via the ignoreClass option. Provide a class name to ignore those cells during filtering. The default is no classes are ignored. An exampled page is included. Thanks to geda0 for the idea.
    • Added a minChars option, thanks to Darius Kazemi, which specifies the minimum number of characters a user must enter into the filter field before filtering occurs. Default is 1, meaning the moment the user begins to type, filtering will occur.
    • Merged Pierre Rudloff’s Bower support.
    • Merged Jason’s minRows bug fix.
    • Added an FAQ file.
    Source code(tar.gz)
    Source code(zip)
jQuery plugin to make HTML tables responsive

FooTable V3 This is a complete re-write of the plugin. There is no upgrade path from V2 to V3 at present as the options and the way the code is writte

FooPlugins 2.1k Dec 19, 2022
A JQuery plugin to create AJAX based CRUD tables.

What is jTable http://www.jtable.org jTable is a jQuery plugin used to create AJAX based CRUD tables without coding HTML or Javascript. It has several

Volosoft 1.1k Dec 21, 2022
jQuery plugin for stacking tables on small screens

stacktable.js The Responsive Tables jQuery plugin for stacking tables on small screens. The purpose of stacktable.js is to give you an easy way of con

John Polacek 1k Nov 30, 2022
An Obsidian plugin to provide an editor for Markdown tables

An Obsidian plugin to provide an editor for Markdown tables. It can open CSV data and data from Microsoft Excel, Google Sheets, Apple Numbers and LibreOffice Calc as Markdown tables from Obsidian Markdown editor.

Ganessh Kumar 112 Dec 31, 2022
jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF

tableExport.jquery.plugin Export HTML Table to CSV DOC JSON PDF PNG SQL TSV TXT XLS (Excel 2000 HTML format) XLSX (Excel 2007 Office Open XML format)

null 918 Dec 29, 2022
jQuery grid plugin

jqGrid jQuery grid plugin jqGrid is an Ajax-enabled JavaScript control that provides solutions for representing and manipulating tabular data on the w

Tony Tomov 2.8k Jan 7, 2023
jQuery plugin to show a tree structure in a table

jQuery treetable jQuery treetable is a plugin for jQuery, the 'Write Less, Do More, JavaScript Library'. With this plugin you can display a tree in an

Ludo van den Boom 734 Nov 14, 2022
Lightweight Grid jQuery Plugin

jsGrid Lightweight Grid jQuery Plugin Project site js-grid.com jsGrid is a lightweight client-side data grid control based on jQuery. It supports basi

Artem Tabalin 1.5k Dec 31, 2022
A stupidly small and simple jQuery table sorter plugin

Stupid jQuery Table Sort This is a stupid jQuery table sorting plugin. Nothing fancy, nothing really impressive. Overall, stupidly simple. Requires jQ

Joseph McCullough 708 Dec 26, 2022
Fixed . Doesn't need any custom css/html. Does what position:sticky can't

jquery.floatThead Documentation & Examples: http://mkoryak.github.io/floatThead/ Float the table header on scroll. No changes to your HTML/CSS are req

Misha Koryak 1.2k Dec 6, 2022
⊞ The modern way to work with tables. Blazing fast facet-filtering, sorting, and searching.

Table Elements The easiest way to integrate Meilisearch into your frontend as a data source for your tables. These components will allow you to kick-s

Open Web 10 Nov 21, 2022
An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor.

Obsidian Excel to Markdown Table An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor. Demo You can paste the copied Excel d

Ganessh Kumar 108 Jan 4, 2023
Shrinks any large data tables into compact and responsive tables

jquery.table-shrinker A Jquery plugin to make HTML Table responsive across all devices, the right way! Demo Click here to see the demo, remember to re

null 29 Sep 11, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
jQuery plugin to make HTML tables responsive

FooTable V3 This is a complete re-write of the plugin. There is no upgrade path from V2 to V3 at present as the options and the way the code is writte

FooPlugins 2.1k Dec 19, 2022
A jQuery plugin for making html tables searchable and sortable with pagination

jQuery.fancyTable A jQuery plugin for making html tables searchable and sortable with pagination. Live demo See a live demo on CodePen Installation Us

null 45 Dec 19, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support.

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022