Debian Codegraph @

docs/example-widget-header-titles.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - headerTitles widget</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link rel="stylesheet" href="css/jq.css">
12 <link href="css/prettify.css" rel="stylesheet">
13 <link href="css/tipsy.css" rel="stylesheet">
14 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
15 <script src="js/jquery-ui.min.js"></script>
16 <script src="js/prettify.js"></script>
17 <script src="js/docs.js"></script>
18 <script src="js/jquery.tipsy.min.js"></script>
19
20 <!-- Tablesorter: required -->
21 <link rel="stylesheet" href="../css/theme.blue.css">
22 <script src="../js/jquery.tablesorter.js"></script>
23
24 <!-- Tablesorter: optional -->
25 <script src="../js/widgets/widget-headerTitles.js"></script>
26
27 <script id="js">$(function() {
28
29 var updateTooltips = function($cell, txt) {
30 // dynamically update tipsy
31 if ($cell.is(':hover')) {
32 $cell
33 .attr({ title : txt, 'original-title': txt })
34 // hide, then show the tooltip to force updating & realignment
35 .tipsy('hide')
36 .tipsy('show');
37 }
38 return txt;
39 };
40
41 $("#table1").tablesorter({
42 theme : 'blue',
43 sortList: [[0,0]],
44 headers : { 4: { sorter: false } },
45 widgets: ['zebra', 'headerTitles'],
46 widgetOptions: {
47 headerTitle_useAria : true,
48 // add tooltip class
49 headerTitle_tooltip : 'tooltip',
50 // manipulate the title as desired
51 headerTitle_callback : updateTooltips
52 }
53 });
54
55 // This table is showing all of the headerTitle widget options
56 $("#table2").tablesorter({
57 theme : 'blue',
58 sortList: [[0,0]],
59 // third click resets the sort
60 sortReset: true,
61 headers : { 4: { sorter: false } },
62 widgets: ['zebra', 'headerTitles'],
63 widgetOptions: {
64 // headerTitle_prefix : 'Sort: ', // option has been deprecated
65 // use aria-label text
66 // e.g. "First Name: Ascending sort applied, activate to apply a descending sort"
67 headerTitle_useAria : false,
68 // add tooltip class
69 headerTitle_tooltip : 'tooltip',
70 // custom titles [ "ascending", "descending", "unsorted" ]
71 headerTitle_cur_text : [ 'Ascending text sort applied', 'Descending text sort applied', 'Currently unsorted' ],
72 headerTitle_cur_numeric : [ 'Ascending numeric sort applied', 'Descending numeric sort applied', 'Currently unsorted' ],
73 headerTitle_nxt_text : [ ' apply ascending text sort', ' apply descending text sort', 'remove sort' ],
74 headerTitle_nxt_numeric : [ ' apply ascending numeric sort', ' apply descending numeric sort', 'remove sort' ],
75
76 // title display; {prefix} adds above prefix
77 // {type} adds the current sort order from above (text or numeric)
78 // {next} adds the next sort direction using the sort order above
79 headerTitle_output_sorted : '{current}; activate to {next}',
80 headerTitle_output_unsorted : '{current}; activate to {next}',
81 headerTitle_output_nosort : 'No sort available',
82 // use this type to override the parser detection result
83 // e.g. use for numerically parsed columns (e.g. dates), but you
84 // want the user to see a text sort, e.g. [ 'text', '', 'numeric' ]
85 // use '' (empty string) to use the default
86 headerTitle_type : ['', '', '', '', '', 'text'],
87 // manipulate the title as desired
88 headerTitle_callback : updateTooltips
89 }
90 });
91
92 // using defaults, no tooltips
93 $("#table3").tablesorter({
94 theme : 'blue',
95 sortList: [[0,0]],
96 headers : { 4: { sorter: false } },
97 widgets: ['zebra', 'headerTitles']
98 });
99
100 // add tooltip
101 $('.tooltip').tipsy({ gravity: 's' });
102
103 // switch aria mode
104 var $state = $('#usearia'),
105 $table1 = $('#table1'),
106 // first table only
107 wo = $table1[0].config.widgetOptions;
108 $('button').on('click', function() {
109 wo.headerTitle_useAria = !wo.headerTitle_useAria;
110 // show current state in demo
111 $state.text( wo.headerTitle_useAria );
112 // force headerTitles widget to update
113 $table1.trigger('refreshHeaderTitle');
114 });
115
116 });</script>
117 </head>
118 <body>
119
120 <div id="banner">
121 <h1>table<em>sorter</em></h1>
122 <h2>headerTitles Widget</h2>
123 <h3>Flexible client-side table sorting</h3>
124 <a href="index.html">Back to documentation</a>
125 </div>
126
127 <div id="main">
128
129 <p></p>
130 <br>
131
132 <div class="accordion">
133
134 <h3><a href="#">Notes</a></h3>
135 <div>
136 <ul>
137 <li>In <span class="version">2.15.7</span>,
138 <ul>
139 <li>Sorry for all of these breaking changes, I should have left this widget in beta.</li>
140 <li>The <code>headerTitle_prefix</code>, <code>headerTitle_text</code>, <code>headerTitle_numeric</code> options has been replaced, in lieu of the new ouput options; sorry for no deprecation notice.</li>
141 <li>Added <code>headerTitle_useAria</code>, <code>headerTitle_tooltip</code>, <code>headerTitle_output_sorted</code>, <code>headerTitle_output_unsorted</code>, <code>headerTitle_output_nosort</code>, <code>headerTitle_cur_text</code>, <code>headerTitle_cur_numeric</code>, <code>headerTitle_nxt_text</code>, <code>headerTitle_nxt_numeric</code>, <code>headerTitle_type</code> &amp; <code>headerTitle_callback</code> options. See the options section below for more details.</li>
142 <li>Added <code>"refreshHeaderTitle"</code> method to force the widget to update.</li>
143 </ul>
144 </li>
145 <li>This widget adds a title to the table headers when they are sorted.</li>
146 <li>Click on any header. You may have to move the mouse off, then back on the header to see the title appear.</li>
147 <li>This widget will not work with the original tablesorter plugin (v2.0.5).</li>
148 <li>The examples uses the <a href="http://onehackoranother.com/projects/jquery/tipsy/">tipsy jQuery plugin </a></li>
149 </ul>
150 </div>
151
152 <h3><a href="#">Options</a></h3>
153 <div>
154 <table class="tablesorter-blue">
155 <colgroup>
156 <col style="width:50px;">
157 <col style="width:120px;">
158 <col>
159 </colgroup>
160 <thead>
161 <tr><th>Option</th><th>Default</th><th>Description</th></tr>
162 </thead>
163 <tbody>
164 <tr>
165 <td>headerTitle_useAria</td>
166 <td><code>false</code></td>
167 <td>
168 When <code>true</code>, the headers titles are extracted from the <code>aria-label</code>. The text in that label is built from the <a href="http://mottie.github.io/tablesorter/docs/#variable-language"><code>$.tablesorter.language</code> option</a>.
169 </td>
170 </tr>
171 <tr>
172 <td>headerTitle_tooltip</td>
173 <td><code>&quot;&quot;</code></td>
174 <td>
175 Add a (tooltip) class name to the header, yeah you could have used the <a href="http://mottie.github.io/tablesorter/docs/#cssheader"><code>cssHeader</code> option</a> to do the same thing, but this option allows adding classes using an array.
176 <pre class="prettyprint lang-js">headerTitle_tooltip : [ 'tooltip-text', 'tooltip-text', 'tooltip-numeric', 'tooltip-numeric', '', 'tooltip-text']</pre>
177 </td>
178 </tr>
179 <tr>
180 <td>
181 headerTitle_cur_text<br>
182 headerTitle_cur_numeric
183 </td>
184 <td>(see description)</td>
185 <td>
186 When any of the header title output options use the <code>{current}</code> tag, it is replaced by values from either the current ("cur") text or numeric option array as determined by the column unsorted state or sort direction.<br>
187 <br>
188 The array must contain text for ascending, descending and unsorted state (in that order). Defaults:
189 <pre class="prettyprint lang-js">headerTitle_cur_text : [ ' sort: A - Z', ' sort: Z - A', 'ly unsorted' ],
190 headerTitle_cur_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'ly unsorted' ]</pre>
191 </td>
192 </tr>
193 <tr>
194 <td>
195 headerTitle_nxt_text<br>
196 headerTitle_nxt_numeric
197 </td>
198 <td>(see description)</td>
199 <td>
200 When any of the header title output options use the <code>{next}</code> tag, it is replaced by values from either the next ("nxt") text or numeric option array as determined by the column unsorted state or sort direction.<br>
201 <br>
202 The array must contain text for when the next state is ascending, descending and unsorted (in that order). Defaults:
203 <pre class="prettyprint lang-js">headerTitle_nxt_text : [ ' sort: A - Z', ' sort: Z - A', 'remove sort' ],
204 headerTitle_nxt_numeric : [ ' sort: 0 - 9', ' sort: 9 - 0', 'remove sort' ]</pre>
205 </td>
206 </tr>
207 <tr>
208 <td>
209 headerTitle_output_sorted<br>
210 headerTitle_output_unsorted<br>
211 headerTitle_output_nosort
212 </td>
213 <td>(see description)</td>
214 <td>
215 Set the output string for each sort condition: sorted, unsorted or sorting disabled.<br>
216 <br>
217 Each of these option strings can include a <code>{name}</code>, <code>{current}</code> and <code>{next}</code> tag.
218 <ul>
219 <li>The <code>{name}</code> tag is replaced by the header text.</li>
220 <li>The <code>{current}</code> tag is replaced by the type-appropriate text from either the <code>headerTitle_cur_text</code> or <code>headerTitle_cur_numeric</code> option.</li>
221 <li>The <code>{next}</code> tag is replaced by the type-appropriate text from either the <code>headerTitle_nxt_text</code> or <code>headerTitle_nxt_numeric</code> option.</li>
222 </ul>
223 Defaults:
224 <pre class="prettyprint lang-js">headerTitle_output_sorted : 'current{current}; activate to {next}',
225 headerTitle_output_unsorted : 'current{current}; activate to {next} ',
226 headerTitle_output_nosort : 'No sort available'</pre>
227 Note: the reason "activate" is used instead of "click" is because the user can also <kbd>Tab</kbd> to the header cell and press <kbd>Enter</kbd> to initiate a sort.
228 </td>
229 </tr>
230 <tr>
231 <td>headerTitle_type</td>
232 <td><code>[]</code></td>
233 <td>Each column type is determined by the parser <code>type</code> value. So, if you want to override a column default type, set this option with an array with the specified column changed to either "text" or "numeric". This is useful when a date column shows as a numeric sort, but you want your users to see it as a text sort.<br>
234 <br>
235 As seen in the second table initialization code below, if an array element is undefined or an empty string, it will not override the default type.
236 <pre class="prettyprint lang-js">headerTitle_type : ['', '', '', '', '', 'text']</pre>
237 </td>
238 </tr>
239 <tr>
240 <td>headerTitle_callback</td>
241 <td><code>null</code></td>
242 <td>
243 This callback function is executed after the title text string has completed processing. Any additional changes, or modifications can be done within this function. This function has two parameters <code>$cell</code> (the header cell as a jQuery object), and the processed text (<code>txt</code>). The function <strong>must</strong> return the text!
244 <pre class="prettyprint lang-js">headerTitle_callback : function($cell, txt) {
245 return txt;
246 }</pre>In this demo, you will notice that this function is used to dynamically update the tooltip.
247 </td>
248 </tr>
249 </tbody>
250 </table>
251 </div>
252
253 <h3><a href="#">Method</a></h3>
254 <div>
255 <h3>Force headerTitle widget update</h3>
256 If you need to programmically force the header title to update, trigger a <code>refreshHeaderTitle</code> event on the table:
257 <pre class="prettyprint lang-js">$('table').trigger('refreshHeaderTitle');</pre>
258 In this demo, this method is used when switching between the default header title and aria-label text.
259 </div>
260
261 </div>
262
263 <h1>Demo</h1>
264 <div id="demo">
265
266 <h3>Tooltip plugin using togglable aria-label text</h3>
267 <button type="button">use aria-label</button>: <span id="usearia" class="bright">true</span>
268
269 <table id="table1">
270 <thead>
271 <tr><th>First Name</th><th>Last Name</th><th>Age</th><th>Total</th><th>Discount</th><th>Date</th></tr>
272 </thead>
273 <tbody>
274 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jan 18, 2001 9:12 AM</td></tr>
275 <tr><td>John</td><td>Evans</td><td>33</td><td>$9.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
276 <tr><td>Clark</td><td>Kent</td><td>22</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
277 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$15.89</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
278 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jul 6, 2006 8:14 AM</td></tr>
279 </tbody>
280 </table>
281
282 <h3>Tooltip plugin with alternative titles</h3>
283 <table id="table2">
284 <thead>
285 <tr><th>First Name</th><th>Last Name</th><th>Age</th><th>Total</th><th>Discount</th><th>Date</th></tr>
286 </thead>
287 <tbody>
288 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jan 18, 2001 9:12 AM</td></tr>
289 <tr><td>John</td><td>Evans</td><td>33</td><td>$9.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
290 <tr><td>Clark</td><td>Kent</td><td>22</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
291 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$15.89</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
292 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jul 6, 2006 8:14 AM</td></tr>
293 </tbody>
294 </table>
295
296 <h3>No Tooltip Plugin</h3>
297 <table id="table3">
298 <thead>
299 <tr><th>First Name</th><th>Last Name</th><th>Age</th><th>Total</th><th>Discount</th><th>Date</th></tr>
300 </thead>
301 <tbody>
302 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jan 18, 2001 9:12 AM</td></tr>
303 <tr><td>John</td><td>Evans</td><td>33</td><td>$9.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
304 <tr><td>Clark</td><td>Kent</td><td>22</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
305 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$15.89</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
306 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jul 6, 2006 8:14 AM</td></tr>
307 </tbody>
308 </table>
309
310 </div>
311
312 <h1>Javascript</h1>
313 <div id="javascript">
314 <pre class="prettyprint lang-javascript"></pre>
315 </div>
316
317 </div>
318
319 </body>
320 </html>