2

I am working on the exercise in the documentation. I would like the date to be sorted (asc) by default when data is first loaded into the table. In other words : when the user load the table, I would like him/her to see the youngest on top of the table (sorting by Date of Birth). I have read all the documentation but didn't find the clue. I tried initialSort as well but wasn't able to fix it.

Any help ? Thanks you for your time

Alexander
  • 1,114
  • 12
  • 20
Claire
  • 21
  • 2
  • 1
    please post a link to a JS fiddle that shows how your table and data are setup. it is hard to offer the correct advice without knowing how things work your end – Oli Folkerd Apr 10 '20 at 14:43

1 Answers1

3

initialSort should work. Have you included the moment.js library, as documentation says?

In this example from my code, it works:

    const dateFormatter = {
        inputFormat:"YYYY-MM-DD HH:mm:ss",
        outputFormat:"DD/MM/YYYY HH:mm:ss",
        invalidPlaceholder:"(invalid date)",
    }

    var myTable = new Tabulator("#table", {
        columns:[ 
            {title:"Date", field: DATE_KEY, formatter:"datetime", formatterParams: dateFormatter },
            {title:"Total cases", field: CASES_KEY},
        ],
        initialSort:[
            {column:DATE_KEY, dir:"desc"}, //sort by this first
        ]
    });
adryx_92
  • 33
  • 6