File: example-option-date-format.html

package info (click to toggle)
jquery-tablesorter 1%3A2.31.3%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,056 kB
  • sloc: javascript: 19,495; sh: 14; makefile: 8
file content (176 lines) | stat: -rw-r--r-- 4,729 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>jQuery tablesorter 2.0 - Changing the date format</title>

	<!-- jQuery -->
	<script src="js/jquery-latest.min.js"></script>

	<!-- Demo stuff -->
	<link rel="stylesheet" href="css/jq.css">
	<link href="css/prettify.css" rel="stylesheet">
	<script src="js/prettify.js"></script>
	<script src="js/docs.js"></script>

	<!-- Tablesorter: required -->
	<link rel="stylesheet" href="../css/theme.blue.css">
	<script src="../js/jquery.tablesorter.js"></script>

	<script id="js">$(function() {
	// call the tablesorter plugin
	$("table").tablesorter({
		theme : 'blue',

		dateFormat : "mmddyyyy", // set the default date format

		// or to change the format for specific columns, add the dateFormat to the headers option:
		headers: {
			0: { sorter: "shortDate" } //, dateFormat will parsed as the default above
			// 1: { sorter: "shortDate", dateFormat: "ddmmyyyy" }, // set day first format; set using class names
			// 2: { sorter: "shortDate", dateFormat: "yyyymmdd" }  // set year first format; set using data attributes (jQuery data)
		}

	});
});</script>
</head>
<body>
<div id="banner">
	<h1>table<em>sorter</em></h1>
	<h2>Changing the date format</h2>
	<h3>Flexible client-side table sorting</h3>
	<a href="index.html">Back to documentation</a>
</div>
<div id="main">

	<p class="tip">
		<em>NOTE!</em>
	</p>
	<ul>
		<li>The dateFormat option was modified in version 2.0.23 (not part of the original plugin).</li>
		<li>The dateFormat option will ONLY work with the <code>shortDate</code> parser.</li>
		<li>The date can be separated by any of the following: slash, dash, period, comma, space(s) or tab (/-., ).</li>
		<li>This date format parser will only work with a four digit year. You can <a href="example-parsers.html">write your own</a> if you need a two digit year parser.</li>
		<li>In versions 2.3+, date formats can be set by column using any of the following methods (they all do the same thing), in order of priority:
			<ul>
				<li>jQuery data <code>data-date-format="mmddyyyy"</code> (see the Javascript block below on how to set it directly; <code>data-dateFormat</code> is equivalent to <code>data-date-format</code>).</li>
				<li>metadata <code>class="{ dateFormat: "mmddyyyy" }"</code>. This requires the metadata plugin.</li>
				<li>headers option <code>headers : { 0 : { dateFormat: "mmddyyyy" } }</code>.</li>
				<li>header class name <code>class="dateFormat-mmddyyyy"</code>.</li>
				<li>Global (all columns) <code>dateFormat</code> option setting.</li>
			</ul>
		</li>
	</ul>


<h1>Demo</h1>
<div id="demo"><table class="tablesorter">
	<thead>
		<tr>
			<th>Date MMDDYYYY</th>
			<th class="sorter-shortDate dateFormat-ddmmyyyy">Date DDMMYYYY</th>
			<th data-sorter="shortDate" data-date-format="yyyymmdd">Date YYYYMMDD</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>8-7-2011</td>
			<td>7-8-2011</td>
			<td>2011-8-7</td>
		</tr>
		<tr>
			<td>11/1/2011 12:34 AM</td>
			<td>1/11/2011 12:34 AM</td>
			<td>2011/11/1 12:34 AM</td>
		</tr>
		<tr>
			<td>12/28/2011</td>
			<td>28/12/2011</td>
			<td>2011/12/28</td>
		</tr>
		<tr>
			<td>6 30 2011</td>
			<td>30 6 2011</td>
			<td>2011 6 30</td>
		</tr>
		<tr>
			<td>11/1/2011 12:35 AM</td>
			<td>1/11/2011 12:35 AM</td>
			<td>2011/11/1 12:35 AM</td>
		</tr>
		<tr>
			<td>3.4.2011</td>
			<td>4.3.2011</td>
			<td>2011.3.4</td>
		</tr>
		<tr>
			<td>07 01-2011 1:15 PM</td>
			<td>01 7-2011 1:15 PM</td>
			<td>2011-7 01 1:15 PM</td>
		</tr>
		<tr>
			<td>04/5,2011</td>
			<td>5/04,2011</td>
			<td>2011,04/5</td>
		</tr>
		<tr>
			<td>11/1/2011 12:34 PM</td>
			<td>1/11/2011 12:34 PM</td>
			<td>2011/11/1 12:34 PM</td>
		</tr>
		<tr>
			<td>1/21 2011</td>
			<td>21.1/2011</td>
			<td>2011/1.21</td>
		</tr>
		<tr>
			<td>5.24-2011</td>
			<td>24.5-2011</td>
			<td>2011-5.24</td>
		</tr>
		<tr>
			<td>07/01-2011 12:15 PM</td>
			<td>01-7/2011 12:15 PM</td>
			<td>2011/7-01 12:15 PM</td>
		</tr>
		<tr>
			<td>10,14,2011</td>
			<td>14,10,2011</td>
			<td>2011,10,14</td>
		</tr>
		<tr>
			<td>09  07    2011</td> <!-- lot of spaces between the numbers -->
			<td>07    09  2011</td>
			<td>2011  09    07</td>
		</tr>
		<tr>
			<td>2 27.2011</td>
			<td>27 2.2011</td>
			<td>2011 2 27</td>
		</tr>
		<tr>
			<td>8	07	2010</td> <!-- separated by tabs -->
			<td>07	8	2010</td>
			<td>2010	8	07</td>
		</tr>
	</tbody>
</table></div>

	<h1>Javascript</h1>
	<div id="javascript">
		<pre class="prettyprint lang-javascript"></pre>
	</div>
	<h1>HTML</h1>
	<div id="html">
		<pre class="prettyprint lang-html"></pre>
	</div>

<div class="next-up">
	<hr />
	Next up: <a href="example-parsers.html">Parser, writing your own &rsaquo;&rsaquo;</a>
</div>

</div>

</body>
</html>