Sortierung nach Datum in DataTables falsch
This commit is contained in:
parent
ec35e4f140
commit
a7427d7458
48
bootstrap/data-table/date-euro.js
Normal file
48
bootstrap/data-table/date-euro.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* This plug-in will provide date sorting for the "dd/mm/YYYY hh:ii:ss"
|
||||||
|
* formatting, which is common in France and other European countries. It can
|
||||||
|
* also be quickly adapted for other formatting as required. Furthermore, this
|
||||||
|
* date sorting plug-in allows for empty values in the column.
|
||||||
|
*
|
||||||
|
* Please note that this plug-in is **deprecated*. The
|
||||||
|
* [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced
|
||||||
|
* functionality and flexibility.
|
||||||
|
*
|
||||||
|
* @name Date (dd/mm/YYYY hh:ii:ss)
|
||||||
|
* @summary Sort date / time in the format `dd/mm/YYYY hh:ii:ss`
|
||||||
|
* @author [Ronan Guilloux](http://coolforest.net/)
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#example').dataTable( {
|
||||||
|
* columnDefs: [
|
||||||
|
* { type: 'date-euro', targets: 0 }
|
||||||
|
* ]
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
|
||||||
|
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
||||||
|
"date-euro-pre": function ( a ) {
|
||||||
|
var x;
|
||||||
|
|
||||||
|
if ( $.trim(a) !== '' ) {
|
||||||
|
var frDatea = $.trim(a).split(' ');
|
||||||
|
var frTimea = (undefined != frDatea[1]) ? frDatea[1].split(':') : [00,00,00];
|
||||||
|
var frDatea2 = frDatea[0].split('/');
|
||||||
|
x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + ((undefined != frTimea[2]) ? frTimea[2] : 0)) * 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = Infinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
},
|
||||||
|
|
||||||
|
"date-euro-asc": function ( a, b ) {
|
||||||
|
return a - b;
|
||||||
|
},
|
||||||
|
|
||||||
|
"date-euro-desc": function ( a, b ) {
|
||||||
|
return b - a;
|
||||||
|
}
|
||||||
|
} );
|
@ -22,6 +22,8 @@
|
|||||||
<script type="text/javascript" src="../bootstrap/data-table/jquery.dataTables.min.js"></script>
|
<script type="text/javascript" src="../bootstrap/data-table/jquery.dataTables.min.js"></script>
|
||||||
<script type="text/javascript" src="../bootstrap/data-table/dataTables.rowReorder.min.js"></script>
|
<script type="text/javascript" src="../bootstrap/data-table/dataTables.rowReorder.min.js"></script>
|
||||||
<script type="text/javascript" src="../bootstrap/data-table/dataTables.bootstrap5.min.js"></script>
|
<script type="text/javascript" src="../bootstrap/data-table/dataTables.bootstrap5.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../bootstrap/data-table/date-euro.js"></script>
|
||||||
|
|
||||||
<!-- icons in nav-->
|
<!-- icons in nav-->
|
||||||
<script src="js/all.js" crossorigin="anonymous"></script>
|
<script src="js/all.js" crossorigin="anonymous"></script>
|
||||||
<link rel="stylesheet" href="../bootstrap/node_modules/bootstrap-icons/font/bootstrap-icons.css">
|
<link rel="stylesheet" href="../bootstrap/node_modules/bootstrap-icons/font/bootstrap-icons.css">
|
||||||
@ -294,17 +296,8 @@
|
|||||||
var table = new DataTable('#myTable', {
|
var table = new DataTable('#myTable', {
|
||||||
rowReorder: true,
|
rowReorder: true,
|
||||||
pageLength: 10,
|
pageLength: 10,
|
||||||
"order": [],
|
order: [[1, 'desc']],
|
||||||
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
|
columnDefs: [{ type: "date-euro", targets: 1 }],
|
||||||
var dateFull = aData.date;
|
|
||||||
var dateFullItems = dateFull.split(' ');
|
|
||||||
var dateDatum = dateFullItems[0];
|
|
||||||
var dateDatumItems = dateDatum.split('.');
|
|
||||||
var dateTime = dateFullItems[1];
|
|
||||||
var dateFormat = dateDatumItems[2] + '-' + dateDatumItems[1] + '-' + dateDatumItems[0] + 'T' + dateTime + ':00Z';
|
|
||||||
|
|
||||||
$(nRow).find('td:nth-of-type(2)').attr('data-sort', dateFormat);
|
|
||||||
},
|
|
||||||
language: {
|
language: {
|
||||||
url: '//cdn.datatables.net/plug-ins/1.13.4/i18n/de-DE.json',
|
url: '//cdn.datatables.net/plug-ins/1.13.4/i18n/de-DE.json',
|
||||||
search: "",
|
search: "",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user