Problem with date and lengthMenu

Problem with date and lengthMenu

StewieStewie Posts: 4Questions: 1Answers: 0

hello guys, I´m using datatables with a js code that I found on web, and it works to order date on format that I need, but when I put it to work together, it is just broke, and I dont understand why? I will put the code that Im using, and any help is really welcome :D

this is the js code that im using and it works without next code that i´ll put a little bit above:

    $.extend($.fn.dataTableExt.oSort, {
            "date-br-pre": function(a) {
            if (a == null || a == "") {
            return 0;
            }
            var brDatea = a.split('/');
            return (brDatea[2] + brDatea[1] + brDatea[0]) * 1;
        },

        "date-br-asc": function(a, b) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },

        "date-br-desc": function(a, b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }
        });

If I put just it, it works:

$(document).ready(function() {
        $('#tickers').dataTable(                            
            {
                columnDefs: [{
                type: 'date-br',
                targets: 0
                }]
            }
        );
    });

and if I put the code that I need that works together like this, so I got an error:

    $(document).ready(function() {
        $('#tickers').dataTable(                            
            {
                columnDefs: [{
                type: 'date-br',
                targets: 0
                }]
            },
           {
                lengthMenu: [[100, -1], [100, "Todos"]]
            }
        );
    });

So, since then thanks for everbody :)

This question has an accepted answers - jump to answer

Answers

  • StewieStewie Posts: 4Questions: 1Answers: 0

    In fact when I use the length menu property with date format property I dont get an error, but the order date is missed, and its order it just wrong :/

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Stewie ,

    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

  • StewieStewie Posts: 4Questions: 1Answers: 0

    Hi @colin,

    sorry for something that I said or did wrong, its my first time here, so I made a Fiddle, and its HERE

    so, as I´ve already said, if I put the code to show 100 and "todos" that is All for you there, its break the code and stop working the date order....but if I take it off, the date order works fine...

    any help is welcome, thanks a lot :)

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921
    Answer ✓

    My suggestion is to use the datetime sorting solution described here:
    https://datatables.net/blog/2014-12-18

    I updated your example with the solution presented:
    https://jsfiddle.net/g7cw26xj/

    Kevin

  • StewieStewie Posts: 4Questions: 1Answers: 0
    edited September 2019

    @kthorngren, or Kevin, thank you so much man, your example just solve my problem, it was exactly what I want, so thanks a lot one more time :)

This discussion has been closed.