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"/>
<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 for some of the original code.
Here is the javascript file:
+1
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
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);
var input2 = document.createElement('input');
input2.setAttribute('type', 'submit');
input2.attributes['type'] = 'submit';
input2.onkeyup = function() {
filterTable(input, element);
}
form.appendChild(input2);
element.parentNode.insertBefore(form, element);
Have fun.
+1
Hello Echarp
I am looking for a table sort script to find names and numbers in a table of about 100 rows.
Your tablefilter script seems to be very good for this job,
so I tested your fiterTable.js script with the browsers: Firefox 2.x; IE 7; Opera 9 and Netscape 7.x.
It runs in all browsers without Netscape(The form field das’nt appear).
In your homepage http://leparlement.org/filterTable it’s ok, also in Netscape.
What did I wrong?
Best Regards
Franz Kruft
+0
-1
+0
-1
-1
-1
+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
-1