Debian Codegraph @

docs/example-widget-grouping.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Grouping Rows Widget</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 <style>
19 /* remove messed up row hovering on this info table */
20 table.classes tr:hover td {
21 background: #fff !important;
22 }
23 </style>
24
25 <style id="css">/* CSS from widget.grouping.css (added v2.28.4) */
26 tr.group-header td {
27 background: #eee;
28 }
29 .group-name {
30 text-transform: uppercase;
31 font-weight: bold;
32 }
33 .group-count {
34 color: #999;
35 }
36 .group-hidden {
37 display: none;
38 }
39 .group-header, .group-header td {
40 user-select: none;
41 -moz-user-select: none;
42 }
43 /* collapsed arrow */
44 tr.group-header td i {
45 display: inline-block;
46 width: 0;
47 height: 0;
48 border-top: 4px solid transparent;
49 border-bottom: 4px solid #888;
50 border-right: 4px solid #888;
51 border-left: 4px solid transparent;
52 margin-right: 7px;
53 user-select: none;
54 -moz-user-select: none;
55 }
56 tr.group-header.collapsed td i {
57 border-top: 5px solid transparent;
58 border-bottom: 5px solid transparent;
59 border-left: 5px solid #888;
60 border-right: 0;
61 margin-right: 10px;
62 }</style>
63
64 <!-- Tablesorter: required -->
65 <link href="../css/theme.blue.css" rel="stylesheet">
66 <script src="../js/jquery.tablesorter.js"></script>
67 <script src="../js/widgets/widget-filter.js"></script>
68
69 <!-- grouping widget -->
70 <!-- <link href="../css/widget.grouping.css" rel="stylesheet"> (added above) -->
71 <script src="../js/parsers/parser-input-select.js"></script>
72 <script src="../js/parsers/parser-date-weekday.js"></script>
73 <script src="../js/widgets/widget-grouping.js"></script>
74 <script src="../js/widgets/widget-storage.js"></script>
75
76 <script id="js">$(function() {
77
78 $("#groups").tablesorter({
79 theme : "blue",
80 headers: {
81 0: { sorter: "checkbox" },
82 3: { sorter: "select" },
83 6: { sorter: "inputs" }
84 // 7: defaults to "shortDate", but set to "weekday-index" ("group-date-weekday") or "time" ("group-date-time")
85 },
86 widgets: [ "group", "columns", "filter", "zebra" ],
87 widgetOptions: {
88 group_collapsible : true, // make the group header clickable and collapse the rows below it.
89 group_collapsed : false, // start with all groups collapsed (if true)
90 group_saveGroups : true, // remember collapsed groups
91 group_saveReset : '.group_reset', // element to clear saved collapsed groups
92 group_count : " ({num})", // if not false, the "{num}" string is replaced with the number of rows in the group
93
94 // apply the grouping widget only to selected column
95 group_forceColumn : [], // only the first value is used; set as an array for future expansion
96 group_enforceSort : true, // only apply group_forceColumn when a sort is applied to the table
97
98 // checkbox parser text used for checked/unchecked values
99 group_checkbox : [ 'checked', 'unchecked' ],
100
101 // change these default date names based on your language preferences (see Globalize section for details)
102 group_months : [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
103 group_week : [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
104 group_time : [ "AM", "PM" ],
105
106 // use 12 vs 24 hour time
107 group_time24Hour : false,
108 // group header text added for invalid dates
109 group_dateInvalid : 'Invalid Date',
110
111 // this function is used when "group-date" is set to create the date string
112 // you can just return date, date.toLocaleString(), date.toLocaleDateString() or d.toLocaleTimeString()
113 // reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Conversion_getter
114 group_dateString : function(date) {
115 return date.toLocaleString();
116 },
117
118 group_formatter : function(txt, col, table, c, wo, data) {
119 // txt = current text; col = current column
120 // table = current table (DOM); c = table.config; wo = table.config.widgetOptions
121 // data = group data including both group & row data
122 if (col === 7 && txt.indexOf("GMT") > 0) {
123 // remove "GMT-0000 (Xxxx Standard Time)" from the end of the full date
124 // this code is needed if group_dateString returns date.toString(); (not localeString)
125 txt = txt.substring(0, txt.indexOf("GMT"));
126 }
127 // If there are empty cells, name the group "Empty"
128 return txt === "" ? "Empty" : txt;
129 },
130
131 group_callback : function($cell, $rows, column, table) {
132 // callback allowing modification of the group header labels
133 // $cell = current table cell (containing group header cells ".group-name" & ".group-count"
134 // $rows = all of the table rows for the current group; table = current table (DOM)
135 // column = current column being sorted/grouped
136 if (column === 2) {
137 var subtotal = 0;
138 $rows.each(function() {
139 subtotal += parseFloat( $(this).find("td").eq(column).text() );
140 });
141 $cell.find(".group-count").append("; subtotal: " + subtotal );
142 }
143 },
144 // event triggered on the table when the grouping widget has finished work
145 group_complete : "groupingComplete"
146 }
147 });
148
149 });</script>
150 </head>
151 <body id="group">
152 <div id="banner">
153 <h1>table<em>sorter</em></h1>
154 <h2>Grouping Rows Widget</h2>
155 <h3>Flexible client-side table sorting</h3>
156 <a href="index.html">Back to documentation</a>
157 </div>
158 <div id="main">
159
160 <p></p>
161 <br>
162
163 <div id="root" class="accordion">
164
165 <h3><a href="#">Notes</a></h3>
166 <div>
167 <ul>
168 <li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version 1.7+.</li>
169 <li>Please do not use this widget in very large tables (it might be really slow) <del>or when your table includes multiple tbodies</del>.<br><br></li>
170
171 <li>In <span class="version updated">v2.28.4</span>, added <code>widget.group.css</code> file into the <code>css</code> folder. It contains the grouping widget css shown on this page.</li>
172 <li>In <span class="version updated">v2.27.6</span>, added <code>group-date-hour</code> group type to the Header Class Names.</li>
173 <li>In <span class="version updated">v2.25.4</span>, the zebra widget is reapplied to the table after opening a collapsed group.</li>
174 <li>In <span class="version">v2.24.1</span>
175 <ul>
176 <li>Added <code>"group-text"</code> group type to the Header Class Names. This class name will use the all of the text from the cell (this would essentially be the same as using "group-word-999").</li>
177 <li>Updated this demo to use the new "weekday-index" parser when the date column is set to "group-date-weekday", and to use the "time" parser when the date column is set to "group-date-time". It is not the most efficient because changing parsers requires an "update".</li>
178 </ul>
179 </li>
180
181 <li>In <span class="version">v2.24.0</span>
182 <ul>
183 <li>This widget now works properly when used with a pager that has the `removeRows` option set to `true`.</li>
184 <li>Added <code>group_time24Hour</code> (set 12 vs 24 hour time) &amp; <code>group_dateInvalid</code> (group header text) options.</li>
185 <li>Improved compatibility of the group widget with jQuery Globalize.</li>
186 <li>The <code>group_months</code> option will now accept a zero or one-based array or object of month names.</li>
187 <li>The <code>group_week</code> option will now accept an object using three-letter English weekday abbreviations as a key.</li>
188 <li>The <code>group_time</code> option will now accept an object using "am" or "pm" as a key.</li>
189 <li>For more detail, see the description column for the option in the Options section below.</li>
190 <li>For information on how to load &amp; use Globalize, see the Globalization section below.</li>
191 </ul>
192 </li>
193 </ul>
194
195 <div class="accordion start-closed">
196 <h3 id="old-notes"><a href="#">Older Notes</a></h3>
197 <div>
198 <ul>
199 <li>In <span class="version">v2.23.3</span>
200 <ul>
201 <li>Added <code>group_forceColumn</code> &amp; <code>group_enforceSort</code> options for force column grouping.</li>
202 <li>Updated method used to save collapsed groups, so any previously collapsed groups will be ignored after this update.</li>
203 </ul>
204 </li>
205 <li>In <span class="version">v2.22.0</span>, group headers are now keyboard accessible using <kbd>Tab</kbd>; and pressing <kbd>Enter</kbd> while the header has focus will toggle the group header, or use <kbd>Shift</kbd> + <kbd>Enter</kbd> to toggle all groups.</li>
206 <li>In <span class="version">v2.21.0</span>
207 <ul>
208 <li>Added <code>group_checkbox</code> option to allow setting the parsed text from the "parser-input-select.js" checkbox parser.</li>
209 <li>Fixed an issue with the filter widget overriding the "group-hidden" class name.</li>
210 </ul>
211 </li>
212 <li>In <span class="version">v2.15.6</span>, added <code>group_saveGroups</code> &amp; <code>group_saveReset</code> options. More details are included in the "Options" section.</li>
213 <li>In <span class="version">v2.14</span>, added <code>group_dateString</code> option. More details are included in the "Options" section.</li>
214 <li>In <span class="version">v2.13</span>, added <code>group_separator</code> option &amp; <code>group-separator-#</code> header class name. To see this in action, check out the <a href="example-parsers-file-type.html">file type parser demo</a>.</li>
215 <li>In <span class="version">v2.12</span>, added <code>group_callback</code> &amp; <code>group_complete</code> options. See options section below for details.</li>
216 <li>In <span class="version">v2.11</span>:
217 <ul>
218 <li>The grouping widget now works across multiple tbodies.</li>
219 <li>Added <code>group-false</code> header option which disables the grouping widget for a specific column.</li>
220 <li>Added the <code>group_collapsed</code> option - get more details in the options block below.</li>
221 <li>You can now toggle <strong>all</strong> group rows by holding down the <kbd>Shift</kbd> key while clicking on a group header.</li>
222 <li>This widget now works properly with the pager addon (pager addon updated).</li>
223 </ul>
224 </li>
225 </ul>
226 </div>
227 </div>
228 </div>
229
230 <h3><a href="#">Options</a></h3>
231 <div>
232 <h4>Group widget default options (added inside of tablesorter <code>widgetOptions</code>)</h4>
233 <div class="tip">
234 <span class="label label-info">TIP!</span> Click on the link in the option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
235 </div>
236 <table class="tablesorter-blue options">
237 <thead>
238 <tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
239 </thead>
240 <tbody>
241 <tr id="group_collapsible">
242 <td><span class="permalink">group_collapsible</span></td>
243 <td><code>true</code></td>
244 <td>
245 when <code>true</code>, the group headers become clickable and collapse the rows below it.
246 </td>
247 </tr>
248 <tr id="group_collapsed">
249 <td><span class="permalink">group_collapsed</span></td>
250 <td><code>false</code></td>
251 <td>
252 when <code>true</code> and <code>group_collapsible</code> is also <code>true</code>, all groups will start collapsed (<span class="version">v2.11</span>)
253 </td>
254 </tr>
255 <tr id="group_savegroups">
256 <td><a href="#" class="permalink">group_saveGroups</a></td>
257 <td><code>true</code></td>
258 <td>Remember collapsed groups (<span class="version">v2.15.6</span>)
259 <div class="collapsible">
260 <ul>
261 <li>This option saves the currently collapsed groups, using the group name.</li>
262 <li>Collapsed groups are saved by column and group class name, so that the groups can be dynamically changed and still remember the correct collapsed groups. Try changing the group names (using the sliders) in the demo below &amp; then collapsing some groups several times; go back to previous groups and it will remember which groups were collapsed.</li>
263 <li>Because the group name is saved, groups with a number range (e.g. "group-number-10"; see the "Numeric" column below) will show a different range depending on sort direction; in this situation, each sort direction is saved independently.</li>
264 <li>This option requires the <code>$.tablesorter.storage</code> utility contained within the <code>jquery.tablesorter.widgets.js</code> file.</li>
265 </ul>
266 </div>
267 </td>
268 </tr>
269 <tr id="group_savereset">
270 <td><a href="#" class="permalink">group_saveReset</a></td>
271 <td><code>null</code></td>
272 <td>Element used to clear saved collapsed groups (<span class="version">v2.15.6</span>)
273 <div class="collapsible">
274 <ul>
275 <li>This option should contain a jQuery selector string or jQuery object pointing to an element to be used to reset (clear) the list of collapsed groups.</li>
276 <li>You can also clear the saved collapsed groups by calling this function: <code>$.tablesorter.grouping.clearSavedGroups(table);</code> (table would be either the table DOM or table jQuery object).</li>
277 <li>This option requires the <code>$.tablesorter.storage</code> utility contained within the <code>jquery.tablesorter.widgets.js</code> file.</li>
278 </ul>
279 </div>
280 </td>
281 </tr>
282 <tr id="group_count">
283 <td><a href="#" class="permalink">group_count</a></td>
284 <td><code>&quot; ({num})&quot;</code></td>
285 <td>
286 Allows you to add custom formatting, or remove, the group count within the group header. Set it to <code>false</code> or an empty string to remove the count.
287 <div class="collapsible">
288 <p><span class="label warning">*NOTE*</span> The value that replaces the <code>{num}</code> placeholder only counts the number of <em>visible</em> rows.</p>
289 </div>
290 </td>
291 </tr>
292 <tr id="group_separator">
293 <td><a href="#" class="permalink">group_separator</a></td>
294 <td><code>&quot;-&quot;</code></td>
295 <td>
296 When the <code>group-separator</code> class name is added, it uses the setting from this option to split the table cell content for grouping <span class="version">v2.13</span>.<br>
297 <div class="collapsible">
298 <br>
299 If your content has mixed separators (e.g. <code>images/cats/burger-time.jpg</code>), you can set this option to use a regular expression:
300 <pre class="prettyprint lang-js">// the above example becomes: ["images", "cats", "burger-time", "jpg"]
301 group_separator : /[/.]/</pre>
302 </div>
303 </td>
304 </tr>
305 <tr id="group_formatter">
306 <td><a href="#" class="permalink">group_formatter</a></td>
307 <td><code>null</code></td>
308 <td>
309 Use this function to modify the group header text before it gets applied.
310 <div class="collapsible">
311 <br>
312 It provides various parameters (<code>txt, col, table, c, wo</code>) to make it work for any of the table columns and data. See the comments in the example below for more details.
313 <ul>
314 <li><code>txt</code> - current text of the group header.</li>
315 <li><code>col</code> - current table column being grouped (zero-based index).</li>
316 <li><code>table</code> - current table (DOM).</li>
317 <li><code>c</code> - table configuration data from <code>table.config</code>.</li>
318 <li><code>wo</code> - table widget options from <code>table.config.widgetOptions</code>.</li>
319 <li><code>data</code> - group &amp; row data. This includes:
320 <ul>
321 <li><code>data.group</code> - (String) Current Group Name. Same as <code>txt</code>.</li>
322 <li><code>data.column</code> - (Number) Current column. Same as <code>col</code>.</li>
323 <li><code>data.$row</code> - (jQuery object) Row at the start of a group (group header is inserted before this row).</li>
324 <li><code>data.rowData</code> - (Array) Parsed data from <code>data.$row</code>; <code>data.rowData[ c.columns ]</code> contains raw row data & any associated child rows.</li>
325 <li><code>data.groupIndex</code> - (Number) <span class="label warning">Do not change</span> - Current group header index.</li>
326 <li><code>data.groupClass</code> - (Array) <span class="label warning">Do not change</span> - Class name applied to the header cell, e.g. <code>'group-letter-1'</code>.</li>
327 <li><code>data.grouping</code> - (Array) <span class="label warning">Do not change</span> - This is the <code>data.groupClass</code> split into its components, e.g. <code>['group','letter','1']</code>.</li>
328 <li><code>data.savedGroup</code> - (Boolean) <span class="label warning">Do not change</span> - Value is <code>true</code> if the group is collapsed & saved to storage.</li>
329 <li><code>data.currentGroup</code> - (String) <span class="label warning">Do not use</span> This value is immediately replaced by the <code>group_formatter</code> returned value.</li>
330 </ul>
331 </li>
332 </ul>
333 <pre class="prettyprint lang-js">group_formatter : function(txt, col, table, c, wo, data) {
334 // If there are empty cells, name the group "Empty"
335 return txt === "" ? "Empty" : txt;
336 }</pre>
337 </div>
338 </td>
339 </tr>
340 <tr id="group_callback">
341 <td><a href="#" class="permalink">group_callback</a></td>
342 <td><code>null</code></td>
343 <td>
344 Use this function to further modify the group header to include more information (i.e. group totals). Parameters include (<code>$cell, $rows, column, table</code>). See the example below for more details <span class="version">v2.12</span>.
345 <div class="collapsible">
346 <ul>
347 <li><code>$cell</code> - current group header table cell (jQuery object).</li>
348 <li><code>$rows</code> - current group rows (jQuery object).</li>
349 <li><code>column</code> - current table column being grouped (zero-based index).</li>
350 <li><code>table</code> - current table (DOM).</li>
351 </ul>
352 <pre class="prettyprint lang-js">group_callback : function($cell, $rows, column, table) {
353 $cell.find('.group-name').append(' group'); // adds "group" to the end of the group name
354 }</pre>
355 </div>
356 </td>
357 </tr>
358 <tr id="group_complete">
359 <td><a href="#" class="permalink">group_complete</a></td>
360 <td><code>&quot;groupingComplete&quot;</code></td>
361 <td>
362 Event triggered on the table when the grouping widget has finished work <span class="version">v2.12</span>.
363 <div class="collapsible">
364 <pre class="prettyprint lang-js">$('table').on('groupingComplete', function() {
365 // always hide empty groups ("Empty" can be added by the group_formatter function)
366 $(this).find('.group-header:contains("Empty")').trigger('toggleGroup');
367 });</pre>
368 </div>
369 </td>
370 </tr>
371
372 <tr id="group_forcecolumn">
373 <td><a href="#" class="permalink">group_forceColumn</a></td>
374 <td><code>[]</code></td>
375 <td>
376 Force the group widget to only apply to one column (<span class="version">v2.23.3</span>).
377 <div class="collapsible">
378 <p>When this option is set, only the first value in the array is used; <em>it is set up as an array for future expansion</em>.</p>
379 <p>When set, the set column will be the only column grouped by this widget.</p>
380 <p>If the <code>group_enforceSort</code> option is set to <code>false</code>, the column will be grouped without a sort applied to the table.</p>
381 </div>
382 </td>
383 </tr>
384
385 <tr id="group_enforcesort">
386 <td><span class="permalink">group_enforceSort</span></td>
387 <td><code>true</code></td>
388 <td>
389 Only allow <code>group_forceColumn</code> to work when a sort is applied to the table (<span class="version">v2.23.3</span>).
390 </td>
391 </tr>
392
393 <tr id="group_checkbox">
394 <td><a href="#" class="permalink">group_checkbox</a></td>
395 <td>(see description)</td>
396 <td>
397 Set checkbox parser text (<span class="version">v2.21.0</span>)
398 <div class="collapsible">
399 <br>
400 The checkbox parser in the "parser-input-select.js" file will use this option to set the group header text displayed for a checkbox state.
401 <p></p>
402 Defaults are: <code>[ &quot;checked&quot;, &quot;unchecked&quot; ]</code>
403 </div>
404 </td>
405 </tr>
406
407 <tr id="group_months">
408 <td><a href="#" class="permalink">group_months</a></td>
409 <td>(see description)</td>
410 <td>
411 Name arrays included so that the language of the date groups can be modified easily (<span class="version updated">v2.24.0</span>; see "Globalization" section for details).
412 <div class="collapsible">
413 <p>Showing defaults (English):</p>
414 <pre class="prettyprint lang-js">// zero-based array
415 group_months: [ &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot; ]</pre>
416 As of <span class="version">v2.24.0</span>, this option will also work with an object with a one-base "index":
417 <pre class="prettyprint lang-js">// get Months list from CLDR (see Globalization section for more info)
418 var months = new Cldr( 'en' ).main([ "dates/calendars/gregorian/months", "format", "abbreviated" ]);
419 // one-based object (CLDR output example)
420 // months = { 1: "Jan", 2: "Feb", 3: "Mar", 4: "Apr", 5: "May", 6: "Jun", 7: "Jul", 8: "Aug", 9: "Sep", 10: "Oct", 11: "Nov", 12: "Dec" }
421 // then in the widgetOptions,
422 group_months: months</pre>
423 A one-based array of month names will also work.
424 <pre class="prettyprint lang-js">group_months: [ "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]</pre>
425 </div>
426 </td>
427 </tr>
428
429 <tr id="group_week">
430 <td><a href="#" class="permalink">group_week</a></td>
431 <td>(see description)</td>
432 <td>
433 Name arrays included so that the language of the date groups can be modified easily (<span class="version updated">v2.24.0</span>; see "Globalization" for details).
434 <div class="collapsible">
435 <p>Showing defaults (English):</p>
436 <pre class="prettyprint lang-js">// zero-based index
437 group_week: [ &quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot; ]</pre>
438 As of <span class="version">v2.24.0</span>, this option will also work with an object using a three-letter English weekday abbreviated names as a key:
439 <pre class="prettyprint lang-js">// get weekdays list from CLDR (see Globalization section for more info)
440 var weekdays = new Cldr( 'en' ).main([ "dates/calendars/gregorian/days", "format", "abbreviated" ]);
441 // week-abbreviation based object
442 // weekdays = { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", fri: "Fri", sat: "Sat" }
443 // then in the widgetOptions,
444 group_week: weekdays</pre>
445 At this point, if you're going to use Globalization, it would be best to use the <code>group_dateString</code> to use <code>globalize.dateFormatter</code> to format the date because not all locales start their week on Sunday.
446 </div>
447 </td>
448 </tr>
449
450 <tr id="group_time">
451 <td><a href="#" class="permalink">group_time</a></td>
452 <td>(see description)</td>
453 <td>
454 Name arrays included so that the language of the date groups can be modified easily (<span class="version updated">v2.24.0</span>; see "Globalization" for details).
455 <div class="collapsible">
456 <p>Defaults (English):</p>
457 <pre class="prettyprint lang-js">group_time: [ &quot;AM&quot;, &quot;PM&quot; ]</pre>
458 As of <span class="version">v2.24.0</span>, this option will also work with an object in this format:
459 <pre class="prettyprint lang-js">// get time of day list from CLDR (see Globalization section for more info)
460 var periods = cldr.main([ "dates/calendars/gregorian/dayPeriods", "format", "abbreviated" ]);
461 /* time of day: CLDR returns this object:
462 peroids = {
463 afternoon1: "in the afternoon",
464 am: "AM",
465 am-alt-variant: "am",
466 evening1: "in the evening",
467 midnight: "midnight",
468 morning1: "in the morning",
469 night1: "at night",
470 noon: "noon",
471 pm: "PM",
472 pm-alt-variant: "pm"
473 }
474 then in the widgetOptions,*/
475 group_time: periods</pre>
476 If you want to use a time of day other than "am" or "pm", then you'll need to use the <code>group_dateString</code> to format the date; see the example in the Globalization section below.
477 </div>
478 </td>
479 </tr>
480
481 <tr id="group_time24hour">
482 <td><span class="permalink">group_time24Hour</span></td>
483 <td><code>false</code></td>
484 <td>Set to <code>true</code> to display time in 24 hour format (<span class="version">v2.24.0</span>).</td>
485 </tr>
486
487 <tr id="group_dateinvalid">
488 <td><span class="permalink">group_dateInvalid</span></td>
489 <td><code>'Invalid Date'</code></td>
490 <td>Message added to the Group header if a date is invalid (<span class="version">v2.24.0</span>).</td>
491 </tr>
492
493 <tr id="group_datestring">
494 <td><a href="#" class="permalink">group_dateString</a></td>
495 <td>(see description)</td>
496 <td>
497 When the <code>&quot;group-date&quot;</code> class name is set on a column, this function is used to format the date string (<span class="version updated">v2.24.0</span>).
498 <div class="collapsible">
499 <p>This is the default function:</p>
500 <pre class="prettyprint lang-js">// you can just return date, date.toLocaleString(), date.toLocaleDateString() or d.toLocaleTimeString()
501 group_dateString : function(date, config, $header ) {
502 return date.toLocaleString();
503 }</pre>
504 Other functions that can be used are <code>date</code> (alone), <code>date.toLocaleString()</code>, <code>date.toLocaleDateString()</code> or <code>d.toLocaleTimeString()</code>. See <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Conversion_getter">this reference</a> for more details.
505 <p>In <span class="version">v2.24.0</span>, this widget was updated to make it easier to use with <a href="https://github.com/jquery/globalize">jQuery Globalize</a>.</p>
506 <p>Additionally, two new parameters were added: <a href="index.html#config"><code>config</code></a> and <code>$header</code> (a jQuery object of the associated header cell).</p>
507 </div>
508 </td>
509 </tr>
510 </tbody>
511 </table>
512 </div>
513
514 <h3><a href="#">Header Class Names</a></h3>
515 <div>
516 <h4>Group header class names (when changing the grouping, notice that the <em>sort doesn't change, just the position and names of the group headers</em>):</h4>
517 <table class="tablesorter-blue classes">
518 <thead>
519 <tr><th>Group type</th><th>Group class name</th><th>Description</th></tr>
520 </thead>
521 <tbody>
522 <tr>
523 <td>Disable</td>
524 <td><code>&quot;group-false&quot;</code></td>
525 <td>Disable grouping of rows for a column (<span class="version">v2.11</span>).</td>
526 </tr>
527
528 <tr>
529 <td rowspan="5">Text</td>
530 <td><code>&quot;group-text&quot;</code></td>
531 <td>Group the rows using all of the text from the column's parsed data.</td>
532 </tr>
533 <tr>
534 <td><code>&quot;group-word&quot;</code></td>
535 <td>Group the rows using the first word it finds in the column's parsed data (same as <code>&quot;group-word-1&quot;</code>).</td>
536 </tr>
537 <tr>
538 <td><code>&quot;group-word-n&quot;</code><span class="remark">*</span></td>
539 <td>Group the rows using the nth word in the column (<code>&quot;n&quot;</code> can be any number).</td>
540 </tr>
541 <tr>
542 <td><code>&quot;group-letter&quot;</code></td>
543 <td>Group the rows using the first letter it finds in the column's parsed data (same as <code>&quot;group-letter-1&quot;</code>).</td>
544 </tr>
545 <tr>
546 <td><code>&quot;group-letter-n&quot;</code><span class="remark">*</span></td>
547 <td>Group the rows using letters 1 through n (if n = 2, then it's the first 2 letters) in the column's parsed data (<code>&quot;n&quot;</code> can be any number).</td>
548 </tr>
549
550 <tr>
551 <td rowspan="2">Number</td>
552 <td><code>&quot;group-number&quot;</code></td>
553 <td>Group the rows by the number it finds in the column (step of one; same as <code>&quot;group-number-1&quot;</code>).</td>
554 </tr>
555 <tr>
556 <td><code>&quot;group-number-n&quot;</code><span class="remark">*</span></td>
557 <td>Group the rows into blocks of every n values. So, if n = 10, the groups will be 0-9, 10-19, 20-29, etc (<code>&quot;n&quot;</code> can be any number).</td>
558 </tr>
559
560 <tr>
561 <td rowspan="2">Separator</td>
562 <td><code>&quot;group-separator&quot;</code></td>
563 <td>Group the rows using the text between the start and first separator that it finds in the column's parsed data (same as <code>&quot;group-separator-1&quot;</code>) (<span class="version">v2.13</span>).</td>
564 </tr>
565 <tr>
566 <td><code>&quot;group-separator-n&quot;</code><span class="remark">*</span></td>
567 <td>Group the rows using the nth separated group in the column (<code>&quot;n&quot;</code> can be any number) (<span class="version">v2.13</span>).</td>
568 </tr>
569
570 <tr>
571 <td rowspan="8">Date</td>
572 <td><code>&quot;group-date&quot;</code></td>
573 <td>Group the rows by full date (this shows the current UTC time corrected for your time zone) - <code>&quot;sorter-shortDate&quot;</code> parser needed.</td>
574 </tr>
575 <tr>
576 <td><code>&quot;group-date-year&quot;</code><span class="remark">*</span></td>
577 <td>Group the rows by year - <code>&quot;sorter-shortDate&quot;</code> parser needed.</td>
578 </tr>
579 <tr>
580 <td><code>&quot;group-date-month&quot;</code><span class="remark">*</span></td>
581 <td>Group the rows by month - <code>&quot;sorter-shortDate&quot;</code> parser needed.</td>
582 </tr>
583 <tr>
584 <td><code>&quot;group-date-monthyear&quot;</code><span class="remark">*</span></td>
585 <td>Group the rows by month &amp; year - <code>&quot;sorter-shortDate&quot;</code> parser needed.</td>
586 </tr>
587 <tr>
588 <td><code>&quot;group-date-day&quot;</code><span class="remark">*</span></td>
589 <td>Group the rows by month/day - <code>&quot;sorter-shortDate&quot;</code> parser needed.</td>
590 </tr>
591 <tr>
592 <td><code>&quot;group-date-week&quot;</code><span class="remark">*</span></td>
593 <td>Group the rows by day of the week - <code>&quot;sorter-weekday-index&quot;</code> parser needed.</td>
594 </tr>
595 <tr>
596 <td><code>&quot;group-date-time&quot;</code><span class="remark">*</span></td>
597 <td>Group the rows by time - <code>&quot;sorter-time&quot;</code> parser needed.</td>
598 </tr>
599 <tr>
600 <td><code>&quot;group-date-hour&quot;</code><span class="remark">*</span></td>
601 <td>Group the rows by each hour - <code>&quot;sorter-time&quot;</code> parser needed.</td>
602 </tr>
603
604 </tbody>
605 </table>
606 <span class="remark">*</span> When sorting some columns, different group headers with the same group name may exist. To make these columns sort specifically by the group you want, you'll need to modify the parser.
607 <p>Before v2.24.1, this demo only used the "shortDate" parser on the date column, so when "group-date-week" or "group-date-time" were set, group headers would repeat.</p>
608 </div>
609
610 <h3><a href="#">Methods</a></h3>
611 <div>
612 <h3>Toggle all Groups</h3>
613 Target the group header(s) and trigger a "toggleGroup" event to show/hide rows associated with that group.
614
615 <pre class="prettyprint lang-js">// "toggle" class name added to a button/link
616 $('.toggle').click(function() {
617 // show/hide all groups - table must be grouped (sorted or force grouping)
618 $('table').find('.group-header').trigger('toggleGroup');
619 return false;
620 });</pre>
621 </div>
622
623 <h3><a href="#">Globalization</a></h3>
624 <div>
625 <h3>jQuery Globalize</h3>
626 These instructions are specific to <a href="https://github.com/jquery/globalize">jQuery Globalize</a>.
627 <p><a href="http://jsfiddle.net/Mottie/4ac5kr3o/15/">Here is a demo</a> showing how all the code comes together; there is no official site with JSON files available to load into the demo, so only the required snippets of CLDR data are included in the demo.</p>
628 <h4>Make sure to include files from:</h4>
629 <ul>
630 <li>jQuery Globalize:
631 <ul>
632 <li>Process CLDR data into usable formats.</li>
633 <li>Install from npm (<code>npm install globalize cldr-data</code>), bower (<code>bower install globalize</code>), or</li>
634 <li>Download from <a href="https://github.com/jquery/globalize">https://github.com/jquery/globalize</a>.</li>
635 <li>Depending on the data in your table, you'll need to <a href="https://github.com/jquery/globalize#pick-the-modules-you-need">pick which modules</a> to include; currently for the date module, you'll need to load the number module first (<a href="https://github.com/jquery/globalize/issues/543">ref</a>).</li>
636 <li>Here is an example of how to load all files from Cdnjs (make sure to use the most recent version):
637 <pre class="prettyprint lang-html">&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize.min.js"&gt;&lt;/script&gt;
638 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/currency.min.js"&gt;&lt;/script&gt;
639 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/number.min.js"&gt;&lt;/script&gt;
640 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/date.min.js"&gt;&lt;/script&gt;
641 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/message.min.js"&gt;&lt;/script&gt;
642 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/plural.min.js"&gt;&lt;/script&gt;
643 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/globalize/1.0.0/globalize/relative-time.min.js"&gt;&lt;/script&gt;
644 </pre>
645 </li>
646 </ul>
647 </li>
648 <li>cldrjs:
649 <ul>
650 <li>Needed by Globalize to traverse CLDR data.</li>
651 <li>Install from npm (<code>npm install cldrjs</code>), bower (<code>bower install cldrjs</code>), or</li>
652 <li>Download from <a href="https://github.com/rxaviers/cldrjs">https://github.com/rxaviers/cldrjs</a>.</li>
653 <li>You will likely need to include all files: <code>cldr.js</code>, <code>event.js</code>, <code>supplemental.js</code> and <code>unresolved.js</code>.</li>
654 <li>Here is an example of how to load all files from Cdnjs (make sure to use the most recent version):
655 <pre class="prettyprint lang-html">&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/cldrjs/0.4.3/cldr.min.js"&gt;&lt;/script&gt;
656 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/cldrjs/0.4.3/cldr/event.min.js"&gt;&lt;/script&gt;
657 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/cldrjs/0.4.3/cldr/supplemental.min.js"&gt;&lt;/script&gt;
658 &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/cldrjs/0.4.3/cldr/unresolved.min.js"&gt;&lt;/script&gt;
659 </pre>
660 </li>
661 </ul>
662 </li>
663 <li>CLDR data:
664 <ul>
665 <li>Needed by Globalize &amp; cldrjs.</li>
666 <li>Install from npm (<code>npm install cldr-data</code>), bower (<code>bower install cldr-data</code>), or</li>
667 <li>Find the latest version from here: <a href="http://cldr.unicode.org/index/downloads">http://cldr.unicode.org/index/downloads</a></li>
668 <li>And download the files from here: <a href="http://unicode.org/Public/cldr/">http://unicode.org/Public/cldr/</a> (it is really hard to find this page).</li>
669 <li>For more information on which json files you'll need to include, check out <a href="https://github.com/jquery/globalize#2-cldr-content">these instructions</a>.</li>
670 </ul>
671 </li>
672 </ul>
673
674 <h4>Initialization</h4>
675 The next step is loading the CLDR data into Globalize; please see <a href="https://github.com/jquery/globalize/blob/master/doc/cldr.md#how-do-i-load-cldr-data-into-globalize">this page</a> for more details.
676
677 <pre class="prettyprint lang-js">
678 // code to show how to load a language using jQuery (make sure it was loaded)
679 $(function() {
680 var hasInitialized = false,
681 loadLanguage = function( lang ) {
682 // Use $.getJSON instead of $.get if your server is not configured to return the
683 // right MIME type for .json files.
684 var files = [];
685 if ( !hasInitialized ) {
686 files = [
687 /* core */
688 $.getJSON( 'cldr-data/supplemental/likelySubtags.json' ),
689 /* currency */
690 $.getJSON( 'cldr-data/supplemental/currencyData.json' ),
691 /* date */
692 $.getJSON( 'cldr-data/supplemental/timeData.json' ),
693 $.getJSON( 'cldr-data/supplemental/weekData.json' ),
694 /* number */
695 $.getJSON( 'cldr-data/supplemental/numberingSystems.json' ),
696 /* plural */
697 $.getJSON( 'cldr-data/supplemental/plurals.json' ),
698 $.getJSON( 'cldr-data/supplemental/ordinals.json' )
699 ];
700 }
701 files = files.concat([
702 /* currency */
703 $.getJSON( 'cldr-data/main/' + lang + '/currencies.json' ),
704 /* date */
705 $.getJSON( 'cldr-data/main/' + lang + '/ca-gregorian.json' ),
706 $.getJSON( 'cldr-data/main/' + lang + '/timeZoneNames.json' ),
707 /* number */
708 $.getJSON( 'cldr-data/main/' + lang + '/numbers.json' ),
709 /* relative time */
710 $.getJSON( 'cldr-data/main/' + lang + '/dateFields.json' ),
711 /* unit */
712 $.getJSON( 'cldr-data/main/' + lang + '/units.json' )
713 ]);
714 $.when
715 .apply( $, files )
716 .then( function() {
717 // Normalize $.get results, we only need the JSON, not the request statuses.
718 return [].slice.apply( arguments, [ 0 ] ).map( function( result ) {
719 return result[ 0 ];
720 });
721 })
722 .then( Globalize.load )
723 .then( function() {
724 if ( !hasInitialized ) {
725 // initialization code goes here
726 }
727 hasInitialized = true;
728 // code to run after each new language has loaded goes here
729 });
730 };
731
732 // initial language load
733 loadLanguage( 'en' );
734 });
735 </pre>
736
737 <h4>Usage</h4>
738 Use Globalize with tablesorter &amp; the group widget inside of the <code>group_dateString</code> callback function.
739 <p>In <span class="version">v2.24.0</span></p>
740 <ul>
741 <li>The <code>group_months</code>, <code>group_week</code> &amp; <code>group_time</code> options were modified to work with CLDR data.</li>
742 <li><code>group_months</code> option will work with either a zero-based array of month names (basic use), or an object with a key using a one-based indexed with a month name value pair (the CLDR format; see the "months" comment in code example below).</li>
743 <li><code>group_week</code> option will work with either a zero-based array of weekday names (basic use), or an object with a key using three letter abbreviations of English weekday names with a localized weekday name value pair (the CLDR format; see the "days of week" comment in the code below).</li>
744 <li><code>group_time</code> option will now accept an object using "am" or "pm" (both lower case) as a key.<br><br></li>
745
746 <li>The <code>group_dateString</code> callback function was updated with two additional parameters to allow access to table data. See the "Options" section above for more details.</li>
747 <li>Check out <a href="http://jsfiddle.net/Mottie/4ac5kr3o/15/">this demo</a> using the code below</li>
748 </ul>
749 <pre class="prettyprint lang-js">$( function() {
750 // using an english example
751 var lang = 'en',
752 cldr = new Cldr( lang ),
753 // Globalize.load already done!!
754 globalize = Globalize.locale( lang ),
755 // months: CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" }
756 months = cldr.main([ "dates/calendars/gregorian/months", "format", "abbreviated" ]),
757 // days of week: CLDR returns { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... }
758 week = cldr.main([ "dates/calendars/gregorian/days", "format", "abbreviated" ]),
759 /* time of day: CLDR returns
760 { afternoon1: "in the afternoon", am: "AM", am-alt-variant: "am", evening1: "in the evening", midnight: "midnight",
761 morning1: "in the morning", night1: "at night", noon: "noon", pm: "PM", pm-alt-variant: "pm" } */
762 periods = cldr.main([ "dates/calendars/gregorian/dayPeriods", "format", "abbreviated" ]);
763
764 $( 'table' ).tablesorter({
765 theme : 'blue',
766 widgets: [ 'group', 'zebra' ],
767 widgetOptions : {
768 group_months : months,
769 group_week : week,
770 // setting group_times to an empty string forces "group-time" to use group_dateString function
771 group_time : periods,
772 group_dateString : function ( date, c, $column ) {
773 // see https://github.com/jquery/globalize/blob/master/doc/api/date/date-formatter.md
774 var hour = date.getHours(),
775 min = date.getMinutes(),
776 format = globalize.dateFormatter({ datetime: "full" })( date ),
777 time = globalize.dateFormatter({ time: "full" })( date );
778 // replace special times with time period
779 if ( hour === 0 && min === 0 ) {
780 // midnight: this method may not work in all locales!
781 return format.replace( time, periods.midnight );
782 } else if ( hour === 12 && min === 0 ) {
783 // noon: this method may not work in all locales!
784 return format.replace( time, periods.noon );
785 }
786 return format;
787 }
788 }
789 });
790
791 });</pre>
792 </div>
793
794 </div>
795
796 <p></p>
797
798 <h1>Demo</h1>
799
800 <ul>
801 <li>Clicking on a sortable header cells will sort the column and group the rows based on the group setting.</li>
802 <li>Clicking on a group header will toggle the view of the content below it.</li>
803 <li>Using <kbd>Shift</kbd> plus Click on a group header will toggle the view of all groups in that table.</li>
804 </ul>
805
806 <span class="demo-label">Numeric column:</span> <div id="slider0"></div> <span class="numberclass"></span> (includes subtotals)<br>
807 <span class="demo-label">Animals column:</span> <div id="slider1"></div> <span class="animalclass"></span><br>
808 <span class="demo-label">Date column:</span> <div id="slider2"></div> <span class="dateclass"></span><sup class="results">&dagger;</sup>
809 <br><br>
810 <button type="button" class="group_reset">Reset Saved Collapsed Groups</button>
811 <div id="demo"><table id="groups">
812 <thead>
813 <tr>
814 <th class="group-word"></th> <!-- checkbox status -->
815 <th class="group-number">Quality (number)</th> <!-- notice this uses the same class name as the Numeric column, it's just left at 1 -->
816 <th class="group-number-10">Numeric (every <span>10</span>)</th>
817 <th class="group-letter-1">Priority (letter)</th>
818 <th class="group-letter-1">Animals (first <span>letter</span>)</th>
819 <th class="group-word-1">Natural Sort (first word)</th>
820 <th class="group-word-2">Inputs (second word)</th>
821 <!-- try "group-date", "group-date-year", "group-date-month", "group-data-monthyear", "group-date-day", "group-date-week" or "group-date-time" -->
822 <th class="group-date">Date (<span>Full</span>)</th>
823 </tr>
824 </thead>
825 <tfoot>
826 <tr>
827 <th></th>
828 <th>Quality</th>
829 <th>Numeric</th>
830 <th>Priority</th>
831 <th>Animals</th>
832 <th>Natural Sort</th>
833 <th>Inputs</th>
834 <th>Date</th>
835 </tr>
836 </tfoot>
837 <tbody>
838 <tr><td><input type="checkbox" checked></td><td>1</td><td>10</td><td><select><option selected>A</option><option>B</option><option>C</option></select></td><td>Koala</td><td>abc 123</td><td><input type="text" value="item: truck" /></td><td>1/13/2013 12:01 AM</td></tr>
839 <tr><td><input type="checkbox"></td><td>3</td><td>29</td><td><select><option>A</option><option>B</option><option selected>C</option></select></td><td>Kangaroo</td><td>abc 1</td><td><input type="text" value="item: car" /></td><td>1/15/2013 4:20 AM</td></tr>
840 <tr><td><input type="checkbox"></td><td>2</td><td>10</td><td><select><option>A</option><option>B</option><option selected>C</option></select></td><td>Ant</td><td>abc 9</td><td><input type="text" value="item: motorcycle" /></td><td>1/13/2013</td></tr>
841 <tr><td><input type="checkbox"></td><td>3</td><td>81</td><td><select><option>A</option><option selected>B</option><option>C</option></select></td><td>Bee</td><td>zyx 24</td><td><input type="text" value="item: golf cart" /></td><td>1/11/2013 12:45 AM</td></tr>
842 <tr><td><input type="checkbox" checked></td><td>3</td><td>21</td><td><select><option>A</option><option selected>B</option><option>C</option></select></td><td>Aardwolf</td><td>zyx 55</td><td><input type="text" value="item: scooter" /></td><td>1/13/2013 3:30 AM</td></tr>
843 <tr><td><input type="checkbox"></td><td>1</td><td>3</td><td><select><option selected>A</option><option>B</option><option>C</option></select></td><td>Bear</td><td>abc 11</td><td><input type="text" /></td><td>1/15/2013</td></tr>
844 <tr><td><input type="checkbox"></td><td>4</td><td>12</td><td><select><option>A</option><option selected>B</option><option>C</option></select></td><td>Armadillo</td><td>zyx 2</td><td><input type="text" /></td><td>1/15/2013 12:30 PM</td></tr>
845 <tr><td><input type="checkbox" checked></td><td>2</td><td>56</td><td><select><option selected>A</option><option>B</option><option>C</option></select></td><td>Aardvark</td><td>abc 2</td><td><input type="text" value="item: skateboard" /></td><td>1/22/2013</td></tr>
846 <tr><td><input type="checkbox"></td><td>1</td><td>55</td><td><select><option selected>A</option><option>B</option><option>C</option></select></td><td>Lion</td><td>abc 9</td><td><input type="text" /></td><td>2/15/2013</td></tr>
847 <tr><td><input type="checkbox" checked></td><td>4</td><td>87</td><td><select><option>A</option><option selected>B</option><option>C</option></select></td><td>Anteater</td><td>ABC 10</td><td><input type="text" value="item: skates" /></td><td>1/3/2013</td></tr>
848 <tr><td><input type="checkbox" checked></td><td>2</td><td>98</td><td><select><option>A</option><option>B</option><option selected>C</option></select></td><td>Lemur</td><td>zyx 1</td><td><input type="text" /></td><td>1/11/2013</td></tr>
849 <tr><td><input type="checkbox"></td><td>1</td><td>20</td><td><select><option>A</option><option>B</option><option selected>C</option></select></td><td>Llama</td><td>zyx 12</td><td><input type="text" /></td><td>12/13/2012</td></tr>
850 </tbody>
851 </table>
852 </div>
853 <small><span class="results">&dagger;</span> When "group-date-week" is set, the parser is changed to "weekday-index". And when "group-date-time" is set, the "time" parser is being used. All other date column settings use the "shortDate" parser.</small>
854 <p></p>
855
856 <h1>Page Header</h1>
857 <div>
858 <pre class="prettyprint lang-html">&lt;!-- Tablesorter: required --&gt;
859 &lt;link href=&quot;css/theme.blue.css&quot; rel=&quot;stylesheet&quot;&gt;
860 &lt;script src=&quot;js/jquery-latest.min.js&quot;&gt;&lt;/script&gt;
861 &lt;script src=&quot;js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
862 &lt;script src=&quot;js/widget-filter.js&quot;&gt;&lt;/script&gt;
863 &lt;script src=&quot;js/widget-storage.js&quot;&gt;&lt;/script&gt;
864
865 &lt;!-- Grouping widget --&gt;
866 &lt;link href=&quot;css/widget.group.css&quot; rel=&quot;stylesheet&quot;&gt; &lt;!-- added v2.28.4 --&gt;
867 &lt;script src=&quot;js/parsers/parser-input-select.js&quot;&gt;&lt;/script&gt;
868 &lt;script src=&quot;js/parsers/parser-date-weekday.js&quot;&gt;&lt;/script&gt;
869 &lt;script src=&quot;js/widgets/widget-grouping.js&quot;&gt;&lt;/script&gt;</pre>
870 </div>
871
872 <h1>Script</h1>
873 <div id="javascript">
874 <pre class="prettyprint lang-js"></pre>
875 </div>
876
877 <h1>CSS</h1>
878 <div id="css">
879 <pre class="prettyprint lang-css"></pre>
880 </div>
881
882 <h1>HTML</h1>
883 <div id="html">
884 <pre class="prettyprint lang-html"></pre>
885 </div>
886
887 <script>
888 /* DEMO ONLY CODE */
889 $(function() {
890 var $groups = $('#groups'),
891 startBlock = 10,
892 startVal = 1,
893 curGroup = 0,
894 numcol = 2,
895 letcol = 4,
896 datecol = 7,
897 dateGroups = [ '', 'year', 'month', 'monthyear', 'day', 'week', 'time', 'hour' ];
898 // Numeric column slider
899 $( "#slider0" ).slider({
900 value: startBlock,
901 min: 10,
902 max: 50,
903 step: 10,
904 create: function() {
905 $('.numberclass').html(' "group-number-' + startBlock + '"');
906 $groups.find('.tablesorter-header-inner:eq(' + numcol + ')').find('span').html(startBlock);
907 },
908 slide: function( event, ui ) {
909 $groups[0].config.$headers.eq(numcol)
910 .attr('class', function(i,v) {
911 return v.replace(/group-number-\d+/, 'group-number-' + ui.value);
912 })
913 .trigger('sorton', [ [[numcol,0]] ]);
914 $('.numberclass').html(' "group-number-' + ui.value + '"');
915 $groups.find('.tablesorter-header-inner:eq(' + numcol + ')').find('span').html(ui.value);
916 }
917 });
918 // animal (letter) column slider
919 $( "#slider1" ).slider({
920 value: startVal,
921 min: 1,
922 max: 5,
923 step: 1,
924 create: function() {
925 $('.animalclass').html(' "group-letter-' + startVal + '"');
926 $groups.find('.tablesorter-header-inner:eq(' + letcol + ')').find('span').html(startVal === 1 ? 'letter' : startVal + ' letters');
927 },
928 slide: function( event, ui ) {
929 $groups[0].config.$headers.eq(letcol)
930 .attr('class', function(i,v) {
931 return v.replace(/group-letter-\d+/, 'group-letter-' + ui.value);
932 })
933 .trigger('sorton', [ [[letcol,0]] ]);
934 $('.animalclass').html(' "group-letter-' + ui.value + '"');
935 $groups.find('.tablesorter-header-inner:eq(' + letcol + ')').find('span').html(ui.value === 1 ? 'letter' : ui.value + ' letters');
936 }
937 });
938 // date column slider
939 $( "#slider2" ).slider({
940 value: curGroup,
941 min: 0,
942 max: dateGroups.length - 1,
943 step: 1,
944 create: function() {
945 $('.dateclass').html(' "group-date' + (curGroup > 0 ? '-' + dateGroups[curGroup] : '') + '"');
946 $groups.find('.tablesorter-header-inner:eq(' + datecol + ')').find('span').html(curGroup === 0 ? 'full' : dateGroups[curGroup]);
947 },
948 slide: function( event, ui ) {
949 var $h = $groups[0].config.$headers.eq(datecol)
950 .attr('class', function(i,v) {
951 return v.replace(/group-date(-\w+)?/, 'group-date' + (ui.value > 0 ? '-' + dateGroups[ui.value] : ''));
952 });
953 $h.removeClass('sorter-weekday-index sorter-time');
954 if ( dateGroups[ui.value] === 'week' ) {
955 $h.addClass('sorter-weekday-index');
956 $groups.trigger('update', [ [[datecol,0]] ]);
957 } else if ( dateGroups[ui.value] === 'time' || dateGroups[ui.value] === 'hour' ) {
958 $h.addClass('sorter-time');
959 $groups.trigger('update', [ [[datecol,0]] ]);
960 } else {
961 $groups.trigger('update', [ [[datecol,0]] ]);
962 }
963 $('.dateclass').html(' "group-date' + (ui.value > 0 ? '-' + dateGroups[ui.value] : '') + '"');
964 $groups.find('.tablesorter-header-inner:eq(' + datecol + ')').find('span').html(ui.value === 0 ? 'full' : dateGroups[ui.value]);
965 }
966 });
967
968 });
969 </script>
970
971 </div>
972
973 </body>
974 </html>