plotly / plotly/dash

implement formating for type='datetime' in dash-table

Open
#2,410 17 comments 18 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dash-data-table feature P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typing page linked in the issue and reproduce the provided dash_table.DataTable example. No source file or test is named in the report, so locate the datetime formatting and native sorting paths from the example. Done means type='datetime' accepts a format and sorts by the underlying date or time rather than the displayed locale string.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.