Skip to content

Commit 54753c2

Browse files
authored
Merge pull request #13 from williamdes/master
Be ready to ship into NPM and clean all the old code
2 parents 347a97c + 55f1d90 commit 54753c2

20 files changed

+586
-6934
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/yarn.lock
3+
/package-lock.json
4+
/*.log

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/test
2+
/demo
3+
/.editorconfig
4+
/node_modules
5+
/yarn.lock
6+
/package-lock.json
7+
/*.log

MIT-LICENSE.txt renamed to LICENSE

File renamed without changes.

README.md

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,31 @@
1-
# uiTableFilter
1+
# Repository
22

3-
- jquery plugin for filtering table rows
3+
[![npm version](https://badge.fury.io/js/jquery-uitablefilter.svg)](https://badge.fury.io/js/jquery-uitablefilter)
44

5-
# alternatives
5+
https://github.com/gregwebs/jquery-uitablefilter
66

7-
This plugin is very light-weight (please [look at the source](https://github.com/gregwebs/jquery-uitablefilter/blob/master/jquery.uitablefilter.js)). I consider it finished, and have no plans to add any features. It works quickly for small data sets without consuming any extra memory (that would be needed for faster filtering).
7+
## What's new ?
8+
With this version the 'column' argument has been modified to be an array of columns instead of being just one column.
9+
Consequently, the script is now able to search in several columns. If you want the original behaviour back, you can put a simple String.
10+
If you don't want to create any filter, just put an empty array as argument.
811

9-
* I have used the [DataTables](http://datatables.net/) plugin when I have greater table needs.
10-
* I recently saw this [fancy tablequeryjs filter](https://github.com/asimihsan/tablequeryjs) plugin.
11-
* There is a [List.js plugin](http://listjs.com/)
12+
## Download
13+
Download the latest version here : https://github.com/gregwebs/jquery-uitablefilter/blob/master/jquery.uitablefilter.js
1214

13-
If you use a javascript framework which keeps the table data in memory (backbone.js, etc)
14-
then all you have to do is add a hook to automatically re-reunder the table.
15-
If you are using a framework like AngularJS the table will be re-rendered automatically.
16-
So it is probably very easy to just roll your own table filter.
15+
## Install
1716

18-
## download
17+
```bash
18+
npm install jquery-uitablefilter
19+
```
20+
or yarn
1921

20-
click Download link at bottom of:
21-
http://plugins.jquery.com/project/uiTableFilter
22+
```bash
23+
yarn add jquery-uitablefilter
24+
```
2225

23-
That link seems to be broken now.
24-
You can simply download the [latest code from github](https://raw.github.com/gregwebs/jquery-uitablefilter/master/jquery.uitablefilter.js)
26+
## Example
27+
Here is an example (see the original project README for more informations). It will search for the word 'Pepper' in #table in columns 'Price', 'Item' and 'ID'.
2528

26-
27-
## source code
28-
29-
http://github.com/gregwebs/jquery-uitablefilter
30-
31-
32-
## author and license
33-
34-
copyright Greg Weber. MIT licensed.
35-
36-
37-
## Demos
38-
39-
### personal
40-
41-
http://projects.gregweber.info/demo/flavorzoom.html
42-
43-
### outside
44-
45-
http://silverwareconsulting.com/index.cfm/2008/10/2/jquery-autofiltering-table
46-
this is a nice example that ties this plugin with the tablesorter plugin
47-
48-
49-
## usage
50-
51-
var t = $('table')
52-
$.uiTableFilter( t, phrase )
53-
54-
55-
arguments:
56-
57-
* jQuery object containing table rows
58-
* phrase to search for
59-
- If the phrase contains spaces it will be broken up into separate words that must all match a row
60-
61-
optional arguments:
62-
$.uiTableFilter( t, phrase, column, ifHidden )
63-
64-
* column to limit search too (the column title in the table header)
65-
* ifHidden - callback to execute if one or more elements was hidden
66-
67-
68-
## Warning:
69-
70-
* expects a thead and tbody element
29+
```js
30+
$.uiTableFilter($('#table'), 'Pepper', ['Price', 'Item', 'D']);
31+
```

demo/flavorzoom.html

Lines changed: 183 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,194 @@
1-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2-
<html><head>
1+
<!DOCTYPE HTML>
2+
<html>
33

4-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Check off the foods you want to eat today.</title>
4+
<head>
55

6-
<link href="flavorzoom_files/flavorzoom.css" rel="stylesheet" type="text/css">
7-
<script type="text/javascript" src="flavorzoom_files/jquery.js"></script>
8-
<script type="text/javascript" src="flavorzoom_files/my_food_plan_pick_foods.js"></script><script type="text/javascript" src="flavorzoom_files/jquery.uitablefilter.js"></script></head><body>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>Check off the foods you want to eat today.</title>
98

9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css"
10+
integrity="sha256-L/W5Wfqfa0sdBNIKN9cG6QA5F2qx4qICmU2VgLruv9Y=" crossorigin="anonymous" />
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.slim.js"
12+
integrity="sha256-sCexhaKpAfuqulKjtSY7V9H7QT0TCN90H+Y5NlmqOUE=" crossorigin="anonymous"></script>
13+
<script type="text/javascript" src="flavorzoom_files/my_food_plan_pick_foods.js"></script>
14+
<script type="text/javascript" src="../jquery.uitablefilter.js"></script>
15+
</head>
1016

11-
<div id="fz_header">
12-
<table width="100%"><tbody><tr>
13-
<td>
14-
Thanks to <a href="http://www.flavorzoom.com">flavorzoom.com</a> for providing a nice example
15-
</td>
16-
<td>
17-
<a href="http://www.flavorzoom.com/"><img src="http://www.flavorzoom.com/images/FZ-Logo-4c-transparent-bg.gif" alt="FlavorZoom"></a>
18-
</td>
19-
</tr>
20-
</tbody></table>
21-
</div>
22-
23-
24-
<div id="mainbody">
17+
<body>
18+
<main role="main">
19+
<div class="container-fluid">
20+
<div class="row">
21+
<div class="col-6">
22+
<h2>Check off the foods you want to eat today.</h2>
2523

26-
<pre>
27-
$(function() {
28-
var theTable = $('table.food_planner')
24+
<form id="filter-form">
25+
<div class="form-inline">
26+
<div class="form-group">
27+
<label for="filter">Filter:</label>
28+
<input name="filter" id="filter" type="text" class="form-control ml-1"
29+
placeholder="Text to search">
30+
</div>
31+
</div>
32+
</form>
2933

30-
theTable.find("tbody > tr").find("td:eq(1)").mousedown(function(){
31-
$(this).prev().find(":checkbox").click()
32-
});
34+
<table class="table table-sm table-striped food_planner">
35+
<thead>
36+
<tr>
37+
<th colspan="2">Your Food List</th>
38+
<tr>
39+
</thead>
40+
<tbody>
41+
<tr>
42+
</tr>
43+
<tr>
44+
<td><input name="food_id_1" value="23558" checked="checked" type="checkbox"></td>
45+
<td>
46+
Beef, ground, 95% lean meat / 5% fat, patty, cooked, broiled<input
47+
name="food_source_row_1" value="USDA" type="hidden"></td>
48+
</tr>
49+
<tr>
50+
<td><input name="food_id_2" value="18061" checked="checked" type="checkbox"></td>
51+
<td>
52+
Bread, rye, toasted<input name="food_source_row_2" value="USDA" type="hidden"></td>
53+
</tr>
54+
<tr>
55+
<td><input name="food_id_3" value="11742" checked="checked" type="checkbox"></td>
56+
<td>
57+
Broccoli, cooked, boiled, drained, with salt<input name="food_source_row_3"
58+
value="USDA" type="hidden"></td>
59+
</tr>
60+
<tr>
61+
<td><input name="food_id_4" value="1001" checked="checked" type="checkbox"></td>
62+
<td>
63+
Butter, salted<input name="food_source_row_4" value="USDA" type="hidden"></td>
64+
</tr>
65+
<tr>
66+
<td><input name="food_id_5" value="6242" checked="checked" type="checkbox"></td>
67+
<td>
68+
CAMPBELL Soup Company, CAMPBELL'S CHUNKY Microwavable Bowls, Chicken and Dumplings
69+
Soup<input name="food_source_row_5" value="USDA" type="hidden"></td>
70+
</tr>
71+
<tr>
72+
<td><input name="food_id_6" value="6396" type="checkbox"></td>
73+
<td>
74+
CAMPBELL Soup Company, CAMPBELL'S CHUNKY Soups, Fajita Chicken with Rice &amp; Beans
75+
Soup<input name="food_source_row_6" value="USDA" type="hidden"></td>
76+
</tr>
77+
<tr>
78+
<td><input name="food_id_7" value="11960" checked="checked" type="checkbox"></td>
79+
<td>
80+
Carrots, baby, raw<input name="food_source_row_7" value="USDA" type="hidden"></td>
81+
</tr>
82+
<tr>
83+
<td><input name="food_id_8" value="1040" checked="checked" type="checkbox"></td>
84+
<td>
85+
Cheese, swiss<input name="food_source_row_8" value="USDA" type="hidden"></td>
86+
</tr>
87+
<tr>
88+
<td><input name="food_id_9" value="7933" checked="checked" type="checkbox"></td>
89+
<td>
90+
Chicken breast, oven-roasted, fat-free, sliced<input name="food_source_row_9"
91+
value="USDA" type="hidden"></td>
92+
</tr>
93+
<tr>
94+
<td><input name="food_id_10" value="14209" checked="checked" type="checkbox"></td>
95+
<td>
96+
Coffee, brewed from grounds, prepared with tap water<input name="food_source_row_10"
97+
value="USDA" type="hidden"></td>
98+
</tr>
99+
<tr>
100+
<td><input name="food_id_11" value="1130" checked="checked" type="checkbox"></td>
101+
<td>
102+
Egg, whole, cooked, omelet<input name="food_source_row_11" value="USDA"
103+
type="hidden">
104+
</td>
105+
</tr>
106+
<tr>
107+
<td><input name="food_id_12" value="18265" checked="checked" type="checkbox"></td>
108+
<td>
109+
English muffins, wheat, toasted<input name="food_source_row_12" value="USDA"
110+
type="hidden">
111+
</td>
112+
</tr>
113+
<tr>
114+
<td><input name="food_id_13" value="15092" type="checkbox"></td>
115+
<td>
116+
Fish, sea bass, mixed species, cooked, dry heat<input name="food_source_row_13"
117+
value="USDA" type="hidden"></td>
118+
</tr>
119+
<tr>
120+
<td><input name="food_id_14" value="18640" checked="checked" type="checkbox"></td>
121+
<td>
122+
HEINZ, WEIGHT WATCHER, Chocolate Eclair, frozen<input name="food_source_row_14"
123+
value="USDA" type="hidden"></td>
124+
</tr>
125+
<tr>
126+
<td><input name="food_id_15" value="42138" checked="checked" type="checkbox"></td>
127+
<td>
128+
Mayonnaise, reduced-calorie or diet, cholesterol-free<input
129+
name="food_source_row_15" value="USDA" type="hidden"></td>
130+
</tr>
131+
<tr>
132+
<td><input name="food_id_16" value="4053" type="checkbox"></td>
133+
<td>
134+
Oil, olive, salad or cooking<input name="food_source_row_16" value="USDA"
135+
type="hidden">
136+
</td>
137+
</tr>
138+
<tr>
139+
<td><input name="food_id_17" value="9203" checked="checked" type="checkbox"></td>
140+
<td>
141+
Oranges, raw, Florida<input name="food_source_row_17" value="USDA" type="hidden">
142+
</td>
143+
</tr>
144+
<tr>
145+
<td><input name="food_id_18" value="20047" checked="checked" type="checkbox"></td>
146+
<td>
147+
Rice, white, long-grain, parboiled, enriched, cooked<input name="food_source_row_18"
148+
value="USDA" type="hidden"></td>
149+
</tr>
150+
<tr>
151+
<td><input name="food_id_19" value="18350" checked="checked" type="checkbox"></td>
152+
<td>
153+
Rolls, hamburger or hotdog, plain<input name="food_source_row_19" value="USDA"
154+
type="hidden">
155+
</td>
156+
</tr>
157+
<tr>
158+
<td><input name="food_id_20" value="14476" type="checkbox"></td>
159+
<td>
160+
Tea, ready-to-drink, LIPTON BRISK iced tea, with lemon flavor<input
161+
name="food_source_row_20" value="USDA" type="hidden"></td>
162+
</tr>
163+
</tbody>
164+
</table>
165+
</div>
166+
<div class="col-6 mt-5">
167+
<pre>
168+
<code>
169+
$(function () {
170+
var theTable = $('table.food_planner')
33171

34-
$("#filter").keyup(function() {
35-
$.uiTableFilter( theTable, this.value );
36-
})
172+
theTable.find("tbody > tr").find("td:eq(1)").mousedown(function () {
173+
$(this).prev().find(":checkbox").click()
174+
});
37175

38-
$('#filter-form').submit(function(){
39-
theTable.find("tbody > tr:visible > td:eq(1)").mousedown();
40-
return false;
41-
}).focus(); //Give focus to input field
42-
});
43-
</pre>
44-
45-
<h2>Check off the foods you want to eat today.</h2>
176+
$("#filter").keyup(function () {
177+
$.uiTableFilter(theTable, this.value);
178+
})
46179

47-
<form id="filter-form">Filter: <input name="filter" id="filter" value="" maxlength="30" size="30" type="text"></form><br>
180+
$('#filter-form').submit(function () {
181+
theTable.find("tbody > tr:visible > td:eq(1)").mousedown();
182+
return false;
183+
}).focus(); //Give focus to input field
184+
});
185+
</code>
186+
</pre>
187+
</div>
188+
</div>
189+
</div>
190+
</main>
48191

49-
<table class="food_planner"><thead><tr><th colspan="2">Your Food List</th><tr></thead>
50-
<tbody><tr style="display: table-row;">
51-
</tr><tr><td><input name="food_id_1" value="23558" checked="checked" id="" style="" type="checkbox"></td><td>
52-
&nbsp; &nbsp; &nbsp;Beef, ground, 95% lean meat / 5% fat, patty, cooked, broiled<input name="food_source_row_1" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_2" value="18061" checked="checked" id="" style="" type="checkbox"></td><td>
53-
&nbsp; &nbsp; &nbsp;Bread, rye, toasted<input name="food_source_row_2" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_3" value="11742" checked="checked" id="" style="" type="checkbox"></td><td>
54-
&nbsp; &nbsp; &nbsp;Broccoli, cooked, boiled, drained, with salt<input name="food_source_row_3" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_4" value="1001" checked="checked" id="" style="" type="checkbox"></td><td>
55-
&nbsp; &nbsp; &nbsp;Butter, salted<input name="food_source_row_4" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_5" value="6242" checked="checked" id="" style="" type="checkbox"></td><td>
56-
&nbsp; &nbsp; &nbsp;CAMPBELL Soup Company, CAMPBELL'S CHUNKY Microwavable Bowls, Chicken and Dumplings Soup<input name="food_source_row_5" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_6" value="6396" id="" style="" type="checkbox"></td><td>
57-
&nbsp; &nbsp; &nbsp;CAMPBELL Soup Company, CAMPBELL'S CHUNKY Soups, Fajita Chicken with Rice &amp; Beans Soup<input name="food_source_row_6" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_7" value="11960" checked="checked" id="" style="" type="checkbox"></td><td>
58-
&nbsp; &nbsp; &nbsp;Carrots, baby, raw<input name="food_source_row_7" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_8" value="1040" checked="checked" id="" style="" type="checkbox"></td><td>
59-
&nbsp; &nbsp; &nbsp;Cheese, swiss<input name="food_source_row_8" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_9" value="7933" checked="checked" id="" style="" type="checkbox"></td><td>
60-
&nbsp; &nbsp; &nbsp;Chicken breast, oven-roasted, fat-free, sliced<input name="food_source_row_9" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_10" value="14209" checked="checked" id="" style="" type="checkbox"></td><td>
61-
&nbsp; &nbsp; &nbsp;Coffee, brewed from grounds, prepared with tap water<input name="food_source_row_10" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_11" value="1130" checked="checked" id="" style="" type="checkbox"></td><td>
62-
&nbsp; &nbsp; &nbsp;Egg, whole, cooked, omelet<input name="food_source_row_11" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_12" value="18265" checked="checked" id="" style="" type="checkbox"></td><td>
63-
&nbsp; &nbsp; &nbsp;English muffins, wheat, toasted<input name="food_source_row_12" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_13" value="15092" id="" style="" type="checkbox"></td><td>
64-
&nbsp; &nbsp; &nbsp;Fish, sea bass, mixed species, cooked, dry heat<input name="food_source_row_13" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_14" value="18640" checked="checked" id="" style="" type="checkbox"></td><td>
65-
&nbsp; &nbsp; &nbsp;HEINZ, WEIGHT WATCHER, Chocolate Eclair, frozen<input name="food_source_row_14" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_15" value="42138" checked="checked" id="" style="" type="checkbox"></td><td>
66-
&nbsp; &nbsp; &nbsp;Mayonnaise, reduced-calorie or diet, cholesterol-free<input name="food_source_row_15" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_16" value="4053" id="" style="" type="checkbox"></td><td>
67-
&nbsp; &nbsp; &nbsp;Oil, olive, salad or cooking<input name="food_source_row_16" value="USDA" type="hidden"></td></tr><tr style="display: table-row;"><td><input name="food_id_17" value="9203" checked="checked" id="" style="" type="checkbox"></td><td>
68-
&nbsp; &nbsp; &nbsp;Oranges, raw, Florida<input name="food_source_row_17" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_18" value="20047" checked="checked" id="" style="" type="checkbox"></td><td>
69-
&nbsp; &nbsp; &nbsp;Rice, white, long-grain, parboiled, enriched, cooked<input name="food_source_row_18" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_19" value="18350" checked="checked" id="" style="" type="checkbox"></td><td>
70-
&nbsp; &nbsp; &nbsp;Rolls, hamburger or hotdog, plain<input name="food_source_row_19" value="USDA" type="hidden"></td></tr><tr><td><input name="food_id_20" value="14476" id="" style="" type="checkbox"></td><td>
71-
&nbsp; &nbsp; &nbsp;Tea, ready-to-drink, LIPTON BRISK iced tea, with lemon flavor<input name="food_source_row_20" value="USDA" type="hidden"></td></tr></tbody></table><br><br></form>
192+
</body>
72193

73-
74-
</div>
75-
76-
</body></html>
194+
</html>

0 commit comments

Comments
 (0)