JSFiddle - React, Tailwind, and code Playground
HTML
<table class="sortable">
<thead>
<tr>
<th >Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>16-07-2014</td>
</tr>
<tr>
<td>28-02-2014</td>
</tr>
<tr>
<td>10-04-2012</td>
</tr>
<tr>
<td>10-04-2016</td>
</tr>
</tbody>
</table>
CSS
td {
background-color: #fff;}
table.sortable th:hover {
cursor: pointer;}
th.ascending, th.descending, table.sortable th:hover {
background-color: #00cccc;
color: #fff;}
/* Arrows for table sorting */
th.ascending:after {
font-size: 60%;
content: '\25B2';
float: left;
padding: 4px 5px 0px 0px;}
th.descending:after {
font-size: 60%;
content: '\25BC';
float: left;
padding: 4px 5px 0px 0px;}
JavaScript
var compare = { // Declare compare object
name: function(a, b) { // Add a method called name
a = a.rep
lace(/^the /i, ''); // Remove The from start of parameter
b = b.replace(/^the /i, ''); // Remove The from start of parameter
if (a < b) { // If value a is less than value b
return -1; // Return -1
} else { // Otherwise
return a > b ? 1 : 0; // If a is greater than b return 1 OR
} // if they are the same return 0
},
duration: function(a, b) { // Add a method called duration
a = a.split(':'); // Split the time at the colon
b = b.split(':'); // Split the time at the colon
a = Number(a[0]) * 60 + Number(a[1]); // Convert the time to seconds
b = Number(b[0]) * 60 + Number(b[1]); // Convert the time to seconds
return a - b; // Return a minus b
},
date: function(a, b) { // Add a method called date
a = new Date(a); // New Date object to hold the date
b = new Date(b); // New Date object to hold the date
return a - b; // Return a minus b
}
};
$('.sortable').each(function() {
var $table = $(this); // This sortable table
var $tbody = $table.find('tbody'); // Store table body
var $controls = $table.find('th'); // Store table headers
var rows = $tbody.find('tr').toArray(); // Store array containing rows
$controls.on('click', function() { // When user clicks on a header
var $header = $(this); // Get the header
var order = $header.data('sort'); // Get value of data-sort attribute
var column; // Declare variable called column
// If...