Black Lives Matter. Please consider donating to Black Girls Code today.

Dash DataTable - Thousands Separator

How can I have thousand’s comma separator in DataTable? Usually, I’d go with plotly layout, but as far as I can see I cannot embed this into a figure as data.

Also some custom data formatting for rows (For example using python’s format f"{x:,.3f}$" for example or something like that

2 Likes

@nmiculinic - For now, you’ll need to convert your data to strings (in whatever format you want) and supply that formatted data as the rows property. There aren’t any built-in formatters in the dash DataTable to do this for you.

I see. The thing is, numbers are ordable (>, <, …) operators work as expected for filtering, but for strings they’re not working. Thus I’d be more than happy to have only thousand’s separator for number without custom formating for now.

1 Like

true…I think we need to add this feature

Hi, I have a similar usecase to have a thousands comma separator in the Datatable. Has there been any update on this, or is t still the old way to convert everything to string?

Thanks to a customer that sponsored this feature, there are now built in formatters :tada:

see https://dash.plot.ly/datatable/typing

I’m still confused. Looked through the documentation, couldn’t find the simple thousands comma separator. Could someone help? thanks

2 Likes

Sweet this is a monumental improvement.
Is it possible to specify a python f-style formatting string for the ‘format’ argument? rather than use the Format() object?

Thanks

It’s not, as we’re actually doing the formatting in the front end (in JavaScript) rather than in Python. However, we designed the Format object to be similar to the Python format string syntax.

I got this working by setting the columns field on my datatable as follows:

import dash_table
from dash_table.Format import Format

dash_table.DataTable(
    id='my-table',
    columns=[
        {'name': 'name', 'id': 'name'},
        {'name': 'number-column', 'id': 'number-column', 'type': 'numeric', 'format': Format(group=',')},
    ],
    data=[],
)

I agree it would be nice to have some more examples in the documentation.

3 Likes