Debian Codegraph @

docs/example-widget-filter-external-inputs.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Filter Widget External Inputs</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
12 <script src="js/jquery-ui.min.js"></script>
13 <link rel="stylesheet" href="css/jq.css">
14 <link href="css/prettify.css" rel="stylesheet">
15 <script src="js/prettify.js"></script>
16 <script src="js/docs.js"></script>
17
18 <!-- Tablesorter: required -->
19 <link rel="stylesheet" href="../css/theme.blue.css">
20 <script src="../js/jquery.tablesorter.js"></script>
21 <script src="../js/widgets/widget-filter.js"></script>
22
23 <script id="js">$(function() {
24
25 var $table = $('table').tablesorter({
26 theme: 'blue',
27 widgets: ["zebra", "filter"],
28 widgetOptions : {
29 // use the filter_external option OR use bindSearch function (below)
30 // to bind external filters.
31 // filter_external : '.search',
32
33 filter_columnFilters: false,
34 filter_saveFilters : true,
35 filter_reset: '.reset'
36 }
37 });
38
39 // Target the $('.search') input using built in functioning
40 // this binds to the search using "search" and "keyup"
41 // Allows using filter_liveSearch or delayed search &
42 // pressing escape to cancel the search
43 $.tablesorter.filter.bindSearch( $table, $('.search') );
44
45 // Basic search binding, alternate to the above
46 // bind to search - pressing enter and clicking on "x" to clear (Webkit)
47 // keyup allows dynamic searching
48 /*
49 $(".search").bind('search keyup', function (e) {
50 $('table').trigger('search', [ [this.value] ]);
51 });
52 */
53
54 // Allow changing an input from one column (any column) to another
55 $('select').change(function() {
56 // modify the search input data-column value (swap "0" or "all in this demo)
57 $('.selectable').attr( 'data-column', $(this).val() );
58 // update external search inputs
59 $.tablesorter.filter.bindSearch( $table, $('.search'), false );
60 });
61
62 });</script>
63
64 </head>
65 <body>
66 <div id="banner">
67 <h1>table<em>sorter</em></h1>
68 <h2>Filter Widget External Inputs</h2>
69 <h3>Flexible client-side table sorting</h3>
70 <a href="index.html">Back to documentation</a>
71 </div>
72 <div id="main">
73
74 <p></p>
75 <br>
76 <div class="accordion">
77
78 <h3><a href="#">Notes</a></h3>
79 <div>
80 <ul>
81 <li>As of <span class="version">v2.18.0</span>,
82 <ul>
83 <li>An external input <code>data-column</code> can now target multiple columns:
84 <ul>
85 <li>When designating a column for an external input, you can now set multiple columns and/or a range of columns (e.g. <code>data-column="0-2,4,6-7"</code>.</li>
86 <li>This type of search acts essentially the same as when the column is set to <code>"all"</code> in that "range", "notMatch" and "operators" searches are ignored.</li>
87 <li>The last search performed using either multiple columns or "all" columns will override all other queries; meaning the other inputs won't clear or update (e.g. performing a search for "foo" in an "all" column search input will override any previous searchs, and the input with a <code>data-column="0-2,4,6-7"</code> will not change its value) - this might be confusing to the user if multiple inputs are visible on the page (placeholder text won't help).</li>
88 <li>The selector in the demo below has two additional options: "Columns 0,3" and "Columns 1-2"; as you can see, switching the column to search between "all", "0,3" and "1-2" does not change the query.</li>
89 </ul>
90 </li>
91 </ul>
92 </li>
93 <li>As of <span class="version">v2.15</span>,
94 <ul>
95 <li>A new filter widget <a href="index.html#widget-filter-external"><code>filter_external</code> option</a> has been added that essentially does the same thing as the <a href="index.html#function-bindsearch"><code>$.tablesorter.bindSearch</code></a> function.</li>
96 <li>Use either to bind external search inputs.</li>
97 <li>To change an input from searching one column (or all columns) to search any other column, call the <code>$.tablesorter.bindSearch</code> function to update the external inputs, even if the inputs are set using the <code>filter_external</code> option. Pass an additional <code>false</code> flag as the last parameter to force the inputs to update.
98 <pre class="prettyprint lang-js">$.tablesorter.bindSearch( $('table'), $('.search'), false );</pre>
99 </li>
100 <li>This demo shows how to use multiple external search filters to filter the table, and how to make one input dynamically change to filter any or all columns.</li>
101 </ul>
102 </li>
103 <li>The <code>$.tablesorter.filter.bindSearch</code> function allows binding multiple external search filters</li>
104 <li>The advantage of using this function over your own is:
105 <ul>
106 <li>Inputs behave the same as internal filters; searches adhere to the <code>filter_liveSearch</code> and <code>filter_searchDelay</code> options.</li>
107 <li>When pressing the <kbd>Esc</kbd> key, the filter resets.</li>
108 </ul>
109 </li>
110 <li>Include a <code>data-column="#"</code> attribute to specify to which column the search should apply; or <code>data-column="all"</code> to search all columns.</li>
111 </ul>
112 </div>
113 </div>
114
115 <h1>Demo</h1>
116
117 <div id="demo"><input class="search selectable" type="search" placeholder="Search" data-column="all">
118 <!-- select to change data-column attribute of the above input -->
119 <select class="change-input">
120 <option value="all">all</option>
121 <option value="0,3">Columns 0,3</option>
122 <option value="1-2">Columns 1-2</option>
123 <option value="0">Rank</option>
124 <option value="1">First Name</option>
125 <option value="2">Last Name</option>
126 </select>
127 <br>
128 <input class="search" type="search" placeholder="First Name" data-column="1"><br>
129 <input class="search" type="search" placeholder="Last Name" data-column="2"><br>
130 <!-- targeted by the "filter_reset" option -->
131 <button type="button" class="reset">Reset Search</button>
132
133 <table class="tablesorter">
134 <thead>
135 <tr>
136 <th>Rank</th>
137 <th>First Name</th>
138 <th>Last Name</th>
139 <th>Age</th>
140 <th>Total</th>
141 <th>Discount</th>
142 <th>Date</th>
143 </tr>
144 </thead>
145 <tbody>
146 <tr><td>1</td><td>Philip Aaron</td><td>Johnson Sr Esq</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td></tr>
147 <tr><td>11</td><td>Aaron</td><td>Hibert</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td></tr>
148 <tr><td>12</td><td>Brandon Clark</td><td>Henry Jr</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td></tr>
149 <tr><td>111</td><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
150 <tr><td>21</td><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
151 <tr><td>013</td><td>Clark</td><td>Kent Sr.</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
152 <tr><td>005</td><td>Bruce</td><td>Almighty Esq</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td></tr>
153 <tr><td>10</td><td>Alex</td><td>Dumass</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td></tr>
154 <tr><td>16</td><td>Jim</td><td>Franco</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td></tr>
155 <tr><td>166</td><td>Bruce Lee</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
156 <tr><td>100</td><td>Brenda Lee</td><td>McMasters</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td></tr>
157 <tr><td>55</td><td>Dennis</td><td>Bronson</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2001 1:12 PM</td></tr>
158 <tr><td>9</td><td>Martha</td><td>delFuego</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td></tr>
159 </tbody>
160 </table></div>
161
162 <h1>Javascript</h1>
163 <div id="javascript">
164 <pre class="prettyprint lang-javascript"></pre>
165 </div>
166
167 <h1>HTML</h1>
168 <div id="html">
169 <pre class="prettyprint lang-html"></pre>
170 </div>
171
172 <div class="next-up">
173 <hr />
174 Next up: <a href="example-widget-filter-custom.html">jQuery custom filter widget &rsaquo;&rsaquo;</a>
175 </div>
176
177 </div>
178
179 </body>
180 </html>