Sort by year-number

Sort by year-number

pippuccio76pippuccio76 Posts: 21Questions: 11Answers: 0

HI i have a table with a culumn formed as year-number .

For example 2024-55

The problem is when i have 2024-6 datatable sort 2024-6 before 2024-55 in desc mode

How can i solve ?

Answers

  • allanallan Posts: 63,966Questions: 1Answers: 10,547 Site admin

    The natural sorting plugin might do the job for you here.

    Allan

  • pippuccio76pippuccio76 Posts: 21Questions: 11Answers: 0

    Hi , i try to use natural sort :

    [CODE]
    $("#tabella-catalogo").DataTable({
    columnDefs: [{
    type: 'natural',
    target: 2
    }],
    order: [
    [2, 'desc'],
    ],
    keys: true,
    responsive: true,
    select: true,
    "language": {
    "sEmptyTable": "Nessun dato presente nella tabella",
    "sInfo": "Vista da START a END di TOTAL Record",
    "sInfoEmpty": "Vista da 0 a 0 di 0 Record",
    "sInfoFiltered": "(filtrati da MAX Record totali)",
    "sInfoPostFix": "",
    "sInfoThousands": ".",
    "sLengthMenu": "Mostra MENU Record",
    "sLoadingRecords": "Caricamento...",
    "sProcessing": "Elaborazione...",
    "sSearch": "Cerca:",
    "sZeroRecords": "Nessun risultato.",
    "oPaginate": {
    "sFirst": "Inizio",
    "sPrevious": "Precedente",
    "sNext": "Successivo",
    "sLast": "Fine"
    },
    "paginate": {
    "previous": "<i class='fas fa-arrow-left'></i>",
    "next": "<i class='fas fa-arrow-right'></i>"
    }
    },
    "drawCallback": function() {
    $(".dataTables_paginate > .pagination").addClass("pagination-rounded");
    }
    });

    [/CODE]

    but doesn't work :

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    Did you load the plugin code?

    I built a simple test case with a sample of your data and it seems to work:
    https://live.datatables.net/wuhemamo/1/edit

    If you still need help then please update my test case to show the issue or provide a link to your page so we can take a look.

    Kevin

Sign In or Register to comment.