Sorting converted epoche dates

Sorting converted epoche dates

dg_datatablesdg_datatables Posts: 53Questions: 10Answers: 1

Hi everyone,
the customer database provides "only" unix time seconds. I easily convert the unix time seconds to date with the render function:

                { data: "startdate>",
                    render: function (data, type, row) {
                        var dtst = "";
                        if (data > 0 && type === "display")
                        {
                            var mydate = new Date(data * 1000);
                            var myyear  = mydate.getFullYear();
                            var mymonth = mymonth.getMonth() +1;
                            var myday  = mydate.getDate();

                            if (mymonth< 10) { mymonth= "0" + mymonth; }
                            if (myday  < 10) { myday  = "0" + myday  ; }

                            dtst = myday  + "." + mymonth + "." + myyear  ;
                        }
                        return dtst;
                    }
                }

This works fine without using the moment.js
But i can't sort this column. Pressing on the sort buttons it has absoluty no effect.

Where am i wrong?

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @dg_datatables ,

    It's because you are always returning an empty string for the sort type - just return data as in this example here.

    Cheers,

    Colin

  • dg_datatablesdg_datatables Posts: 53Questions: 10Answers: 1

    Sorry - I'm blind!
    I do not see a difference between your Code and mine. Your Code is working, but where is the difference?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Ha, very subtle change - it's the first line in the render function:

    var dtst = data;
    
  • dg_datatablesdg_datatables Posts: 53Questions: 10Answers: 1
    edited May 2019

    Oh yessssss
    Thank's a lot for your help.

This discussion has been closed.