dash-table icon indicating copy to clipboard operation
dash-table copied to clipboard

Feature request: implement formating for type='datetime'

Open zdenop opened this issue 5 years ago • 7 comments

According typing page formatting can be configured only type='numeric'.

I would like to use locale datetime formating for datatime. E.g. something like 'locale' in folowing example:


import dash
import dash_table
import pandas as pd
from collections import OrderedDict

df = pd.DataFrame(OrderedDict([
    ('city', ['NYC', 'Montreal', 'Los Angeles']),
    ('max', [108, 99, 111]),
    ('max_date', ['1926-07-22', '1975-08-01', '1939-09-20']),
    ('min', [-15, -36, 28]),
    ('min_date', ['1934-02-09', '1957-01-15', '1913-01-07'])
]))

df.max_date = pd.to_datetime(df.max_date).dt.date
df.min_date = pd.to_datetime(df.min_date)
df['locale'] = df.min_date.apply(lambda x: x.strftime('%a, %x'))

app = dash.Dash(__name__)

app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df.columns],
    style_cell_conditional=[
        {
            'if': {'column_id': 'max_date'},
            'textAlign': 'left',
            'type': 'datetime',
            'format': '%x, %a',
        }],
    data=df.to_dict('records'),
    sort_mode="multi",
    sort_action="native",
    )

if __name__ == '__main__':
    app.run_server(debug=True)

image

Problem of this example is that sorting of 'locale' is based on alphabet and I would like to have sorting based on date(time)

zdenop avatar Feb 18 '20 14:02 zdenop

+1 for this.

This should be a base feature of the package.

gioxc88 avatar Jun 06 '20 08:06 gioxc88

At a high level, what needs to be built out/implemented in order for datetime formatting to work? Are there any known roadblocks or is this currently being worked on in some capacity?

bormanjo avatar Jul 21 '20 20:07 bormanjo

Another +1 for this. There is a workaround in formatting the data as a string before you place it in the table, but then sorting, conditionals, etc are much harder (if not impossible) to utilize.

zach-morris avatar Aug 11 '20 23:08 zach-morris

Any progress on this? It'd be a really useful feature for dealing with timedelta/timestamps.

dsanner avatar Oct 06 '21 16:10 dsanner

Hi @dsanner,

I have bumped into the same difficulty as you all do for this request.

First and foremost, this request has been there for at least one year and no one has been assigned to look into it and Dash 2.0 has been released. I'm pretty sure you could guess the trend from here.

According to posting of @alexcjohnson https://community.plotly.com/t/is-it-any-way-to-set-format-of-date-time-in-datatable/29514, it seems like there is no plan to enhance this request.

Please feel free to correct me @alexcjohnson.

viper7882 avatar Oct 25 '21 01:10 viper7882

That's correct, no work has been done on this issue. It's on our radar but hasn't bubbled up to the top. We've had some internal discussions about how to support internationalization/localization, and this could certainly be intertwined with that, but in any event there will be use cases for table-level and column-level overrides. If anyone is interested in working on this before it makes it to the top of the pile for Plotly staff, we would be happy to help you with any sticking points in making a PR.

alexcjohnson avatar Oct 25 '21 15:10 alexcjohnson

+1 for the feature! Just do it guys, it's super important🙏🏽

tribumirkov avatar Oct 05 '22 23:10 tribumirkov

+1 as well - would be a great feature

l47y avatar Nov 16 '22 14:11 l47y