Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Datatable Templates shared across the whole app

Is it possible to create Datatable templates to be used across the app. The idea is to define a set of parameters that are common between most of my tables.

Hi @JmsBlah, you could try to modularize your code. Lets say you want to use the same template for all tables to target the property ‘style_data_conditional’. Then you could define it as a function inside the file commonmodules.py:

def get_style_data_conditional():
    style_data_conditional = [<your code>]
    return style_data_conditional

Then you simply call that in each table:

dash_table.DataTable(
                id='table',
                columns=columns,
                data=df.to_dict('records'),
                style_data_conditional=commonmodules.get_style_data_conditional()
            )

I hope this is what you are looking for.

Hi @HansPeter123,
that will definitely help, yes.
Do you know if there is a way to return more than one property using one single function as you suggested?

@JmsBlah, do I understand it correctly that you want to define multiple DataTable properties inside one function? Like style_cell, style_cell_conditional, style_data_conditional, etc

Also can do variations of this:

def MyCustomTable(**kwargs):
    return dash_table.DataTable(editable=True, **kwargs)

app.layout = MyCustomTable(data=[...])

(taken from Inherit Interactivity/properties in DataTable)

1 Like

@chriddyp
Yeah. Thats what I was trying just now, I got the idea from the solution proposed by @HansPeter123
Thank you both!

1 Like