I’m so happy with myself, I want to share some nice and easy code that can search and filter in a table.
Simple, nothing to add in your html but for the javascript file and a simple filterable class to set onto tables and to define with a color (or any other style you want).
<style>
.highlighted { background: yellow; }
</style>
<script type="text/javascript"
src="attachment/file/filterTable/filterTable.js"></script>
<table class="filterable">
<thead>
<tr>
<th></th>
<th>Title 1</th>
<th>Title 2</th>
<th>Title 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data</td>
<td>Data again</td>
<td>Data yet other</td>
<td>Data still</td>
</tr>
</tbody>
</table>
| Country | Current US$ | 1990 US$ |
|---|---|---|
| United States | $18.5billion | $5.4bn |
| Russia | $4.6billion | $6.2bn |
| France | $4.4bn | $2.1bn |
| UK | $1.9bn | $985million |
| Germany | $900m | $1.1bn |
| Canada | $900m | $543m |
| China | $700m | $125m |
| Israel | $500m | $283m |
See also “here”:http://www.vonloesch.de/node/23 for some of the original code.
Here is the javascript file:
+1
New discussion
Answer
I like this script, but am trying to use it on a large table (4 columns and about 165 rows), so it is slow. Do you have any suggestions for how to speed it up? When I add a submit button it does help, but still takes about 10-15 seconds to return the search results.
+2
New discussion
Answer
You could try removing some of the features.
For example the script is checking and highlighting individual words, can be removed easily (see the “dehighlight” and highlight" methods).
Already this should give you more reactivity over a large table.
+1
+1
This is an awesome script, nice and lightweight an does the job perfectly, thanks :)
+2
New discussion
Answer
Hi Echarp
i like the filtertable js and have used it in one of my apps, but find it to slow when filtering a large table, is it possible to change to a ‘click serach button or hit enter’ so it doesnt filter live
simpleinvoices.sf.net/demo
Cheers
Justin Kelly
justin@kelly.org.au
+1
New discussion
Answer
It’s a pleasure to create something that can be useful!!!
To improve it on a large table, yes, you would need to move the filtering code toward a “submit” button.
Just modify the javascript, something like:
var form = document.createElement(‘form’); form.setAttribute(‘class’, ‘filter’); __ For ie… form.attributes[‘class’].value = ‘filter’; var input = document.createElement(‘input’); form.appendChild(input);Have fun.
+1
Hello Echarp
+0
Hi Echarp
i like the filtertable js and have used it in one of my apps, but find it to slow when filtering a large table, is it possible to change to a click serach button or hit enter so it doesnt filter live
simpleinvoices.sf.net/demo
Cheers
Justin Kelly
justin@kelly.org.au
+1
New discussion
Answer
Hi Echarp
i like the filtertable js and have used it in one of my apps, but find it to slow when filtering a large table, is it possible to change to a click serach button or hit enter so it doesnt filter live
simpleinvoices.sf.net/demo
Cheers
Justin Kelly
justin@kelly.org.au
+1
New discussion
Answer