Hi,
I’m using datatable to show a list of months, it works fine but it does show months in alphabetical order instead of chronological.
I need it to show months like “january, february, march etc”
this is what i’ve done so far
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-range-pre": function ( a ) {
var monthArr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
return monthArr.indexOf(a);
},
"date-range-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-range-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
$(document).ready(function() {
var dataTable = $('#lista_pagamenti').DataTable({
"processing": true,
"serverSide": true,
"scrollX": true, // Permette lo scroll orizzontale su mobile
// columnDefs permette di gestire lo stile di ogni singola colonna, tioo allinemaento testo etc
'columnDefs': [
{ "sType": "date-range", "targets": 0, }
],
"language": {
"sEmptyTable": "Nessun dato presente nella tabella",
"sInfo": "Vista da _START_ a _END_ di _TOTAL_ elementi",
"sInfoEmpty": "Vista da 0 a 0 di 0 elementi",
"sInfoFiltered": "(filtrati da _MAX_ elementi totali)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "Visualizza _MENU_ elementi",
"sLoadingRecords": "Caricamento...",
"sProcessing": '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Elaborazione...</span>',
"sSearch": "Cerca:",
"sZeroRecords": "La ricerca non ha portato alcun risultato.",
"oPaginate": {
"sFirst": "Inizio",
"sPrevious": "Precedente",
"sNext": "Successivo",
"sLast": "Fine"
},
"oAria": {
"sSortAscending": ": attiva per ordinare la colonna in ordine crescente",
"sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
}
},
buttons: [
{
extend: 'print',
className: 'btn dark btn-outline',
messageTop: 'PDF created by PDFMake with Buttons for DataTables.',
exportOptions: {
columns: [0, 1]
}
},
{
extend: 'copy',
className: 'btn red btn-outline',
exportOptions: {
columns: [0, 1]
}
},
{
extend: 'pdfHtml5',
className: 'btn green btn-outline',
pageSize: 'A4',
title: 'Lista dettagli clienti registrati',
exportOptions: {
columns: [0, 1]
}
},
{
extend: 'colvis',
className: 'btn dark btn-outline',
text: 'Columns'
}
],
"dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"sDom": '<"top"fl>rt<"bottom"ip><"clear">',
"ajax": {
url: "../controllers/ctrl_client_flat_app/ctrl_client_get_payment_list.php",
type: "POST",
async: 'true',
}
});
// Mostro il pulsante strumenti per esportare i dati della tabella
$('#sample_3_tools > li > a.tool-action').on('click', function() {
var action = $(this).attr('data-action');
$('#lista_pagamenti').DataTable().button(action).trigger();
});
}); // Fine document ready