Debian Codegraph @

docs/example-widget-filter-formatter-select2.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Filter Formatter: select2 (beta)</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="../docs/css/jq.css">
14 <link href="../docs/css/prettify.css" rel="stylesheet">
15 <script src="../docs/js/prettify.js"></script>
16 <script src="../docs/js/docs.js"></script>
17
18 <!-- Tablesorter: required -->
19 <link href="../css/theme.blue.css" rel="stylesheet">
20 <script src="../js/jquery.tablesorter.js"></script>
21 <script src="../js/jquery.tablesorter.widgets.js"></script>
22
23 <!-- Select2 code -->
24 <link href="css/select2-3.4.6.min.css" rel="stylesheet">
25 <script src="js/select2-3.4.6.min.js"></script>
26 <script src="../js/widgets/widget-filter-formatter-select2.js"></script>
27
28 <script id="js">$(function() {
29
30 $('.tablesorter').tablesorter({
31 theme: 'blue',
32 widthFixed: true,
33 widgets: ['zebra', 'stickyHeaders', 'filter'],
34 widgetOptions : {
35 // Use the $.tablesorter.storage utility to save the most recent filters
36 filter_saveFilters : true,
37 // jQuery selector string of an element used to reset the filters
38 filter_reset : 'button.reset',
39 // add custom selector elements to the filter row
40 filter_formatter : {
41
42 // Alphanumeric (match)
43 0 : function($cell, indx) {
44 return $.tablesorter.filterFormatter.select2( $cell, indx, {
45 match : true, // adds "filter-match" to header
46 cellText : 'Match: ', // Cell text
47 width: '85%', // adjusted width to allow for cell text
48 value: ['abc', 'def'] // initial values
49 });
50 },
51
52 // Alphanumeric (exact)
53 1 : function($cell, indx) {
54 return $.tablesorter.filterFormatter.select2( $cell, indx, {
55 match : false // exact match only
56 });
57 }
58 },
59
60 // option added in v2.16.0
61 filter_selectSource : {
62 // Alphanumeric match (prefix only)
63 // added as select2 options (you could also use select2 data option)
64 0 : function(table, column) {
65 return ['abc', 'def', 'zyx'];
66 }
67 }
68 }
69
70 });
71
72 });
73 </script>
74
75 </head>
76 <body>
77 <div id="banner">
78 <h1>table<em>sorter</em></h1>
79 <h2>Filter Formatter: select2 (beta)</h2>
80 <h3>Flexible client-side table sorting</h3>
81 <a href="index.html">Back to documentation</a>
82 </div>
83 <div id="main">
84
85 <p></p>
86 <br>
87
88 <div id="root" class="accordion">
89
90 <h3><a href="#">Notes</a></h3>
91 <div>
92 <ul>
93 <li>Updated in <span class="version updated">v2.19.0</span> to properly escape regexp characters. See <a href="https://github.com/Mottie/tablesorter/issues/796">issue #796</a> for details.</li>
94 <li>Updated in <span class="version updated">v2.16.3</span> to allow adding an initial value to the select2 plugin.</li>
95 <li>This is a demo of the select2 filter formatter code.</li>
96 <li>It requires jQuery 1.7.2+, tablesorter <span class="version">2.16</span>+, the filter widget 2.16+ and <a href="http://ivaynberg.github.io/select2/">Select2</a> v3.4.6+ (not tested on older select2 versions)</li>
97 <li>This demo uses the new <a href="index.html#widget-filter-selectsource"><code>filter_selectSource</code></a> option which is only available in tablesorter <span class="version">v2.16</span>+</li>
98 </ul>
99 </div>
100
101 <h3><a href="#">Options</a></h3>
102 <div>
103 There are only two filter formatter options, the rest are all <a href="http://ivaynberg.github.io/select2/#documentation">select2 plugin options</a> (defaults shown below):
104 <table class="tablesorter-blue">
105 <thead>
106 <tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
107 </thead>
108 <tbody>
109 <tr><th colspan="3">Select2 FilterFormatter options</th></tr>
110 </tbody>
111 <tbody>
112
113 <tr>
114 <td>cellText</td>
115 <td>''</td>
116 <td>Text added within a <code>&lt;label&gt;</code> before the input.</td>
117 </tr>
118
119 <tr>
120 <td>match</td>
121 <td>true</td>
122 <td>Adds a "filter-match" class name to the header &amp; modifies the search</td>
123 </tr>
124
125 <tr>
126 <td>value</td>
127 <td>[ ]</td>
128 <td>Set the initial select2 values within this array. These values are restored when the filters are reset.</td>
129 </tr>
130
131 </tbody>
132 <tbody>
133 <tr><th colspan="3">Select2 plugin (modified defaults)</th></tr>
134 </tbody>
135
136 <tbody>
137
138 <tr>
139 <td>multiple</td>
140 <td>true</td>
141 <td>Allow multiple selections. This option can be modified.</td>
142 </tr>
143
144 <tr>
145 <td>width</td>
146 <td>'100%'</td>
147 <td>Reduce this width if you add anything cellText, or the text and the input will be on separate lines.</td>
148 </tr>
149
150 </tbody>
151 </table>
152
153 This is an example of how to set these options:
154 <pre class="prettyprint lang-js">filter_formatter : {
155 // default settings on first column
156 0 : function($cell, indx) {
157 return $.tablesorter.filterFormatter.select2( $cell, indx, {
158 // *** select2 filter formatter options ***
159 cellText : '', // Text (wrapped in a label element)
160 match : true, // adds "filter-match" to header & modifies search
161 value : [], // initial select2 values
162
163 // *** ANY select2 options can be included below ***
164 // (showing default settings for this formatter code)
165 multiple : true, // allow multiple selections
166 width : '100%' // reduce this width if you add cellText
167 });
168 }
169 }</pre>
170 </div>
171 </div>
172
173 <p></p>
174
175 <h1>Demo</h1>
176 <div id="demo"><button type="button" class="reset">Reset Search</button>
177 <table class="tablesorter">
178 <thead>
179 <tr>
180 <!-- filter-match is automatically added by select2 "match" option -->
181 <th>AlphaNumeric (match)</th>
182 <th class="filter-onlyAvail">AlphaNumeric (exact; only available)</th>
183 <th>Numeric</th>
184 <th>Animals</th>
185 <th>Sites</th>
186 </tr>
187 </thead>
188 <tbody>
189 <tr><td>abc 123</td><td>abc 123</td><td>10</td><td>Koala</td><td>http://www.google.com</td></tr>
190 <tr><td>abc 1</td><td>abc 1</td><td>34</td><td>Ox</td><td>http://www.yahoo.com</td></tr>
191 <tr><td>abc 9</td><td>abc 9</td><td>10</td><td>Girafee</td><td>http://www.facebook.com</td></tr>
192 <tr><td>zyx 24</td><td>zyx 24</td><td>67</td><td>Bison</td><td>http://www.whitehouse.gov/</td></tr>
193 <tr><td>abc 11</td><td>abc 11</td><td>3</td><td>Chimp</td><td>http://www.ucla.edu/</td></tr>
194 <tr><td>def 2</td><td>def 2</td><td>56</td><td>Elephant</td><td>http://www.wikipedia.org/</td></tr>
195 <tr><td>abc 9</td><td>abc 9</td><td>75</td><td>Lion</td><td>http://www.nytimes.com/</td></tr>
196 <tr><td>def 10</td><td>def 10</td><td>87</td><td>Zebra</td><td>http://www.google.com</td></tr>
197 <tr><td>zyx 1</td><td>zyx 1</td><td>99</td><td>Koala</td><td>http://www.mit.edu/</td></tr>
198 <tr><td>zyx 12</td><td>zyx 12</td><td>0</td><td>Llama</td><td>http://www.nasa.gov/</td></tr>
199 </tbody>
200 </table></div>
201
202 <h1>Header</h1>
203 <div>
204 <pre class="prettyprint lang-html">&lt;!-- jQuery --&gt;
205 &lt;script src=&quot;js/jquery-latest.min.js&quot;&gt;&lt;/script&gt;
206
207 &lt;!-- Tablesorter: required --&gt;
208 &lt;link href=&quot;../css/theme.blue.css&quot; rel=&quot;stylesheet&quot;&gt;
209 &lt;script src=&quot;../js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
210 &lt;script src=&quot;../js/jquery.tablesorter.widgets.js&quot;&gt;&lt;/script&gt;
211
212 &lt;!-- Select2 code --&gt;
213 &lt;link href=&quot;http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.min.css&quot; rel=&quot;stylesheet&quot;&gt;
214 &lt;script src=&quot;http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.min.js&quot;&gt;&lt;/script&gt;
215 &lt;script src=&quot;../js/widgets/widget-filter-formatter-select2.js&quot;&gt;&lt;/script&gt;</pre>
216 </div>
217
218 <h1>HTML</h1>
219 <div id="html">
220 <pre class="prettyprint lang-html"></pre>
221 </div>
222
223 <h1>Javascript</h1>
224 <div id="javascript">
225 <pre class="prettyprint lang-javascript"></pre>
226 </div>
227
228 </div>
229
230 </body>
231 </html>