Hi
I have noticed that the cell formatting is handled by a Format class which is nice to have but would it be possible to provide a function or lambda function to transform the data in cell to be viewed differently?
For example,
from dash_table.Format import Format
will import the Format class and then is is used in
dash_table.DataTable(
data=df.to_dict('records'),
columns=[
{
'name': i,
'id': i,
'type': 'numeric',
'format': Format(
nully='N/A'
)
} for i in df.columns
],
editable=True
)
Would it be possible to provide a function there that accepts the cell value as input and returns the formatted string to the view of the cell? I was thinking about date display.
import datetime
dash_table.DataTable(
data=df.to_dict('records'),
columns=[
{
'name': i,
'id': i,
'type': 'numeric',
'format': (lambda x: datetime.strptime(str(x),'%Y%m%d').strftime('%d-%b-%Y'))
)
} for i in df.columns
],
editable=True
)
In this example with no error trapping it should take an int or string YYYYmmdd and reformat the date for presentation. The nice side benefit is that from a sorting perspective the underlying data will be ordered timewise correctly. Adding arguments from the local context would be also possible where the function is a lambda function. If this is already possible then I have not been able to find it in the documentation.
This approach could be used for many different types of custom transformation of the data where we don’t want to change the underlying data model but would like to display differently.
This could simplify the formatting of the data while giving more flexibility to the designer.
Any interest Plotly?
Thanks
M