Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabulator sorting data by default

Tags:

tabulator

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

like image 927
Claire Avatar asked Sep 16 '25 18:09

Claire


1 Answers

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
        ]
    });
like image 144
adryx_92 Avatar answered Sep 23 '25 11:09

adryx_92