DATA BRASIL NÃO ORDENA, COMO FAÇO PARA ORDENAR POR DATA DD/MM/YYYY

DATA BRASIL NÃO ORDENA, COMO FAÇO PARA ORDENAR POR DATA DD/MM/YYYY

dmbsitesdmbsites Posts: 3Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • dmbsitesdmbsites Posts: 3Questions: 1Answers: 0

    ESTA MOSTRANDO A ORDENAÇÃO ASSIM:
    10/03/2020
    11/02/2020
    20/01/2020

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,292Questions: 26Answers: 4,768
    Answer ✓

    Try the solution presented in the date sorting blog.

    Kevin

  • rf1234rf1234 Posts: 2,807Questions: 85Answers: 406
    edited May 2020

    You would simply need moment.js with the Brazilian locale file and the ultimate date sorting plug-in which requires moment.js.

    <!-- Moment.js: -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
    
    <!-- Brazilian locale file for moment.js-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/pt-br.js"></script>
    
    <!-- Ultimate date sorting plug-in-->
    <script src="https://cdn.datatables.net/plug-ins/1.10.21/sorting/datetime-moment.js"></script>
    

    In your Javascript you would need these statements. The statements must be executed prior to data table initialization. That should do the trick:

    moment.locale('pt-br');
    $.fn.dataTable.moment( 'L', 'pt-br' );
    

    As you can see in the brazilian locale file 'L' is defined like this:

    longDateFormat : {
        LT : 'HH:mm',
        LTS : 'HH:mm:ss',
        L : 'DD/MM/YYYY',
        LL : 'D [de] MMMM [de] YYYY',
        LLL : 'D [de] MMMM [de] YYYY [às] HH:mm',
        LLLL : 'dddd, D [de] MMMM [de] YYYY [às] HH:mm'
    },
    
  • dmbsitesdmbsites Posts: 3Questions: 1Answers: 0

    resolvido!! obrigado
    coloquei isso $.fn.dataTable.moment( 'DD/MM/YYYY' );

    olhei neste link:
    https://datatables.net/blog/2014-12-18

This discussion has been closed.