Problem with sorting dates DD-MM-YYYY HH:mm:ss -http://prntscr.com/8tluk9 screenshot of the problem
Problem with sorting dates DD-MM-YYYY HH:mm:ss -http://prntscr.com/8tluk9 screenshot of the problem
tomandquery
Posts: 3Questions: 2Answers: 0
Hi! Thanks a lot in advance for help!!
I Have a problem with this format: DD-MM-YYYY HH:mm:ss, it is NOT sortable, please help make it sortable in the table. http://prntscr.com/8tluk9 -screenshot of the problem.
How can I make it be sortable - the second column.
The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" />
<script src="jquery-2.1.4.min.js"></script>
<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src="http://cdn.datatables.net/plug-ins/1.10.9/sorting/datetime-moment.js"></script>
<script>
$(document).ready(function() {
$('#example').DataTable( {
"sPaginationType": "full_numbers",
"aLengthMenu": [[10, 20, 50, -1], [10, 20, 50, "Wszystkie"]],
"bStateSave": true,
"order": [0, 'desc'],
"ordering": true,
});
$.fn.dataTable.moment( 'DD-MM-YYYY HH:mm:ss' );
});
</script>
</head>
<body style="padding:150px;">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Start date</th><th>End date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Start date</th><th>End date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>2012/31/08 14:22:55</td><td>05-07-2011 14:54:50</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>2010/06/12 02:57:52</td><td>31-08-2012 14:22:55</td>
<td>$170,750</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>2010/12/10 02:57:52</td><td>31-08-2012 14:22:55</td>
<td>$170,750</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>2011/05/17 14:54:50</td><td>09-12-2060 02:57:52</td>
<td>$433,060</td>
</tr>
</tbody>
</table></head><body></body></html>
http://prntscr.com/8tluk9
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
$.fn.dataTable.moment( 'DD-MM-YYYY HH:mm:ss' );
line before the DataTable initialisationInstructions on how to format code using Markdown can be found here - I've edited your post to add that.
Allan
I am sorry for that mess... I'm new here as you see :) Anyway thank you a lot for that quick answer and instructions. Table works fine, wish you all the best!