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

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

Then you simply call that in each table:


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

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

1 Like