dash-table
dash-table copied to clipboard
Feature request: implement formating for type='datetime'
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)
Problem of this example is that sorting of 'locale' is based on alphabet and I would like to have sorting based on date(time)
+1 for this.
This should be a base feature of the package.
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?
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.
Any progress on this? It'd be a really useful feature for dealing with timedelta/timestamps.
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.
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.
+1 for the feature! Just do it guys, it's super important🙏🏽
+1 as well - would be a great feature