How to sort date time columns || Como ordenar la columna por fecha y dia

How to sort date time columns || Como ordenar la columna por fecha y dia

ZamuPazZamuPaz Posts: 12Questions: 2Answers: 0

I am trying to get sorting column in datetime by following below link but it is not working for me.

https://datatables.net/blog/2014-12-18

In this case:

$.fn.dataTable.ext.errMode = 'none';
$.dataTable.moment('MM/dd/yyyy HH:mm:ss');

format date:
MM/dd/yyyy HH:mm - 28/12/201 08:00

https://ibm.com/support/knowledgecenter/es/SSHEB3_3.3.2/com.ibm.tap.doc_3.3.2/loc_topics/c_custom_date_formats.html

$(document).ready(function () {
$.fn.dataTable.ext.errMode = 'none';
$.fn.dataTable.moment('dd/MM/yyyy HH:mm');
let TableList = $('#example')
table = TableList.DataTable({
autoWidth: true,
dom: "Bfrtip",
lengthChange: true,
ordering: true,
pageLength: 12,
responsive: true,
sAjaxDataProp: "",
select: true,
ajax: {
url: '{% url 'api_mostrar_programacion_nave' %}',
type: "POST",
data: {
csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value
}
},
});
});

help me please !

Replies

  • ZamuPazZamuPaz Posts: 12Questions: 2Answers: 0
    edited January 2018

    @rf1234 ty for u answer. im from Peruvian and using google translate for the publications and my lenguage is Spanish.

    I'm trying this code.

    <script type="text/javascript" src="{% static 'js/dataTable/es.js' %}"></script>
    <script type="text/javascript" src="{% static 'js/dataTable/datetime-moment.js' %}"></script>
    <script type="text/javascript" src="{% static 'js/dataTable/moment.min.js' %}"></script>
    
    moment.locale('es');
    $.fn.dataTable.moment('dd/MM/yyyy HH:mm');;
    let TableList = $('#example')
    $(document).ready(function () {
                table = TableList.DataTable({
                    autoWidth: true,
                    dom: "Bfrtip",
                    lengthChange: true,
    
    

    Am I having problems with the format of the dates or am I putting the code wrong? (Check photo format date)

    Translate google, sorry

  • rf1234rf1234 Posts: 2,983Questions: 87Answers: 421

    probably the same issue that the Italian guy had in the second example above. The date format that you would like is 20/12/2016 which is "DD/MM/YYYY" and not "dd/MM/yyyy"

    Take a look at the Spanish locale file please. In that file you find this:

     longDateFormat : {
            LT : 'H:mm',
            LTS : 'H:mm:ss',
            L : 'DD/MM/YYYY',
            LL : 'D [de] MMMM [de] YYYY',
            LLL : 'D [de] MMMM [de] YYYY H:mm',
            LLLL : 'dddd, D [de] MMMM [de] YYYY H:mm'
    

    And if you take a look at this: https://momentjs.com/
    and scroll down and select "Spanish" you'll see what those longDateFormats will be formatted to. It is actually this:

    moment.locale();         // es
    moment().format('LT');   // 14:42
    moment().format('LTS');  // 14:42:49
    moment().format('L');    // 23/01/2018
    moment().format('l');    // 23/1/2018
    moment().format('LL');   // 23 de enero de 2018
    moment().format('ll');   // 23 de ene. de 2018
    moment().format('LLL');  // 23 de enero de 2018 14:42
    moment().format('lll');  // 23 de ene. de 2018 14:42
    moment().format('LLLL'); // martes, 23 de enero de 2018 14:42
    moment().format('llll'); // mar., 23 de ene. de 2018 14:42
    

    As you can see the format that you desire is not on that list which means the locale file won't really help you at all because what you need is actually a combination of longDateFormats L and LT. You don't want LLLL.

    I would try the following (without using the locale file):

    $.fn.dataTable.moment('DD/MM/YYYY H:mm');
    
  • rf1234rf1234 Posts: 2,983Questions: 87Answers: 421

    I see you've edited your question. So format LLLL is gone :smile:

    This combination doesn't really make sense by the way:

    moment.locale('es');
    $.fn.dataTable.moment('dd/MM/yyyy HH:mm');
    

    because if you are not using the date formats of the locale files there is no need to specify a locale. This is only useful if you are using those formats and have multiple languages on your site.

    So just use

    $.fn.dataTable.moment('DD/MM/YYYY H:mm');
    

    and you should be ok. No need for the locale file then.

  • ZamuPazZamuPaz Posts: 12Questions: 2Answers: 0
    edited January 2018

    @rf1234 TY, its great, but it's very confusing all this format.

    What is the difference?
    $.fn.dataTable.moment('dd/MM/yyyy HH:mm');;

    $.fn.dataTable.moment('DD/MM/YYYY H:mm'); (This is correct)

    Ty @rf1234

  • rf1234rf1234 Posts: 2,983Questions: 87Answers: 421

    well Javascript is case sensitive ... I didn't invent this stuff, mate :smile: We all have to live with it.

  • ZamuPazZamuPaz Posts: 12Questions: 2Answers: 0

    Yes, u have reason. Thank you very much for the information.

This discussion has been closed.