Tabulator: Setting date field format to MM/DD/YYYY

Created on 11 May 2018  路  5Comments  路  Source: olifolkerd/tabulator

Hi Oli,

Thanks a ton for your response to my previous post. It gave me the lead and was greatly helpful.

Do we have an easy way to format date to MM/DD/YYYY. My date field is displayed as YYYY/MM/DD.

I am under the impression that date formatter is only for sorting

{title:"due_at", field:"due_at", sorter:"date", sorterParams:{format:"DD/MM/YY"}},

any help is appreciated

Question - Ask On Stack Overflow

Most helpful comment

Hey @ryhill

As @Nyut0n says there is no in-built date formatter, only a date sorter.

It would be really easy to write your own formatter for this, if you want to process dates, then i strongly recommend using the moment.js date library.

a basic formatter would be:

//custom date formatter
var dateFormatter = function(cell, formatterParams){
    var value = cell.getValue();

    if(value){
        value = moment(value , "YYYY/MM/DD").format("MM/DD/YYYY");
    }

    return value;
}

//in column definition
{title:"due_at", field:"due_at", formatter:dateFormatter}

Let me know if that helps.

Cheers

Oli :)

All 5 comments

There is no date formatter in Tabulator (yet). What you have there is solely for sorting indeed.
Just create a custom formatter function that returns your preferred date string using moment.js

Hey @ryhill

As @Nyut0n says there is no in-built date formatter, only a date sorter.

It would be really easy to write your own formatter for this, if you want to process dates, then i strongly recommend using the moment.js date library.

a basic formatter would be:

//custom date formatter
var dateFormatter = function(cell, formatterParams){
    var value = cell.getValue();

    if(value){
        value = moment(value , "YYYY/MM/DD").format("MM/DD/YYYY");
    }

    return value;
}

//in column definition
{title:"due_at", field:"due_at", formatter:dateFormatter}

Let me know if that helps.

Cheers

Oli :)

Thanks Oli. You are born to save lives and time. A big boon to developers community

Hi Oli,

I am generating columns dynamically from DB.

[{"title":"Task Due Date","field":"tasks.due_at","formatter":"dateFormatter"}]

I get an error like 'Formatter Error - No such formatter found: dateFormatter'

Any help on this

Thanks

KIRAN

Hey @ryhill

that is because you are trying to use a string to call a function, only inbuilt tabulator formatters can be called using a string.

To do this with your custom formatter you would need to extend the formatter extension. which is really easy, you can find documentation on how to do that Here

I hope that helps,

Cheers

Oli :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mconnelley picture mconnelley  路  3Comments

KES777 picture KES777  路  3Comments

Manbec picture Manbec  路  3Comments

KES777 picture KES777  路  3Comments

AndrewHutcheson picture AndrewHutcheson  路  3Comments