Sorting data DD/MM/YYYY

Sorting data DD/MM/YYYY

pippuccio76pippuccio76 Posts: 19Questions: 10Answers: 0

HI this is my code :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Datatable</title>


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

</head>
<body>

<

div class='table-responsive'>

            <table id='datatable' class='table table-striped table-bordered  table-advance table-hover'>

                <thead>

                    <tr> 

<th>Cliente</th>

<th>Data</th>

<th>Ora Partenza</th>

<th>Ora Arrivo</th>

<th>Luogo Partenza</th>

<th>Luogo Arrivo</th>

<th>Note</th>

        </tr>

                </thead>

                <tbody>





   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 13-02-2017</td>

<td> 04:00</td>

<td> 04:30</td>

<td> Barberino Di Mugello</td>

<td> Trani</td>

<td> pto</td>

</tr>

   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 28-02-2017</td>

<td> 00:45</td>

<td> 02:00</td>

<td> Campobasso</td>

<td> Pescara</td>

<td>Viaggio a </td>

</tr>

   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 02-03-2017</td>

<td> 03:45</td>

<td> 04:00</td>

<td> Pisa</td>

<td> Napoli</td>

<td> </td>

</tr>

   <tr> 

<td>

  Hotel Excelsior

</td>

<td> 03-03-2017</td>

<td> 00:45</td>

<td> 03:45</td>

<td> Catania</td>

<td> Palermo</td>

<td> 25</td>

</tr>

   <tr> 

<td>

  Hotel Astor

</td>

<td> 03-03-2017</td>

<td> 00:00</td>

<td> 00:45</td>

<td> Barberino Di Mugello</td>

<td> Palermo</td>

<td> </td>

</tr>

   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 07-03-2017</td>

<td> 04:45</td>

<td> 09:00</td>

<td> Trani</td>

<td> Caltanissetta</td>

<td> aaa</td>

</tr>

   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 27-02-2017</td>

<td> 05:15</td>

<td> 08:45</td>

<td> Piazza Armerina</td>

<td> Enna</td>

<td> </td>

</tr>

   <tr> 

<td>

  Hotel Baglioni

</td>

<td> 17-03-2017</td>

<td> 04:30</td>

<td> 05:15</td>

<td> Catania</td>

<td> Trani</td>

<td> prova nota </td>

</tr>

</tbody>

   </table>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap.min.js"></script>


<script>

  $(document).ready(function() {
    var handleDataTableButtons = function() {
      if ($('#datatable-buttons').length) {
        $('#datatable-buttons').DataTable({
          dom: 'Bfrtip',
          buttons: [
            {
              extend: 'copy',
              className: 'btn-sm'
            },
            {
              extend: 'csv',
              className: 'btn-sm'
            },
            {
              extend: 'excel',
              className: 'btn-sm'
            },
            {
              extend: 'pdfHtml5',
              className: 'btn-sm'
            },
            {
              extend: 'print',
              className: 'btn-sm'
            },
          ],
          responsive: true
        });
      }
    };

    TableManageButtons = function() {
      'use strict';
      return {
        init: function() {
          handleDataTableButtons();
        }
      };
    }();


    $('#datatable-keytable').DataTable({
      keys: true
    });

    $('#datatable-responsive').DataTable();

    $('#datatable-scroller').DataTable({
      ajax: 'js/datatables/json/scroller-demo.json',
      deferRender: true,
      scrollY: 380,
      scrollCollapse: true,
      scroller: true
    });

    $('#datatable-fixed-header').DataTable({
      fixedHeader: true
    });

    var $datatable = $('#datatable-checkbox');

    $datatable.on('draw.dt', function() {
      $('input').iCheck({
        checkboxClass: 'icheckbox_flat-green'
      });
    });


    TableManageButtons.init();
  });




</script>


<!-- /Datatables -->


$(document).ready(function() { $.fn.dataTable.moment( 'MM/DD/YYYY' ); $('#datatable').DataTable(); } );

</body>
</html>

How can i sort the date ?

Answers

  • kthorngrenkthorngren Posts: 21,175Questions: 26Answers: 4,923

    Looks like you need to load the moment plug-in and change your function to $.fn.dataTable.moment( 'DD/MM/YYYY' );.

    Kevin

  • pippuccio76pippuccio76 Posts: 19Questions: 10Answers: 0
    edited March 2017

    Sorry for the identation , this is ma run code :

    lemuria.altervista.org/datatables/

    If u see i load the plugin with this :


    and i reduce the script as this :

    `
    <script>

      $(document).ready(function() {
    
    
    
         $.fn.dataTable.moment( 'MM/DD/YYYY' );
    
         $('#datatable').DataTable();
      });
    
    
    
    
    </script>
    

    `

  • kthorngrenkthorngren Posts: 21,175Questions: 26Answers: 4,923

    looks like you need to change your moment function to this to match your table's date format:
    $.fn.dataTable.moment( 'DD-MM-YYYY' );

    Kevin

  • pippuccio76pippuccio76 Posts: 19Questions: 10Answers: 0

    Ok it works,tanks , but how can i order the table when i load the page by date?

  • kthorngrenkthorngren Posts: 21,175Questions: 26Answers: 4,923

    You can set the initial sort order with order.

    Kevin

This discussion has been closed.