# Apply same callback to multiple DataTables

**URL:** <https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776>\
**Category:** Dash Python\
**Created:** [May 20, 2020, 4:09am UTC](https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776 "2020-05-20T04:09:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirk77](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kirk77](https://community.plotly.com/u/kirk77)\
**Post date:** [May 20, 2020, 4:09am UTC](https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776/1 "2020-05-20T04:09:34Z")

</div>

Hello,

I am using Upload component and to upload multiple files(number of files are dynamic. i used this code to upload multiple files: [https://dash.plotly.com/dash-core-components/upload](https://dash.plotly.com/dash-core-components/upload)) and converting each file into a dataframe and putting them in separate dataTables(so one dataTable for each file uploaded). I want to apply some call backs which are applicable for all tables. e.g when I select a column in a table, I need to apply a color to all cells in that column (‘style\_data\_conditional’).

Now how can I apply this call back to all the dataTables as it is applicable to all dataTables. I tried 2 ways, once giving same id to all the dataTables and just gave 1 call back and it did not work. I tried another way of giving sequence id with common prefix(e.g table-1, table2…tablen) as id to each of the dataTable. Now how to I loop through each dataTable to apply same callback. Please help.

---

<div class="post-metadata">

**Author:** ![russellthehippo](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/russellthehippo/32/25312_2.png) [@russellthehippo](https://community.plotly.com/u/russellthehippo)\
**Post date:** [May 20, 2020, 6:22pm UTC](https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776/2 "2020-05-20T18:22:43Z")

</div>

You should be able to use a new feature, pattern-matching callbacks, to do this.

> [@mega Dash v1.11.0 Release - Introducing Pattern-Matching Callbacks](https://community.plotly.com/t/dash-v1-11-0-release-introducing-pattern-matching-callbacks/37592/2):
>
> We are very excited about Pattern-Matching callbacks! This is one of the biggest features & deepest overhauls to Dash’s core architecture that we’ve made since we originally released the framework in 2017. In August 2017, one month after we released Dash, we opened up a forum topic about one of the framework’s core limitations: [Dynamic Controls and Dynamic Output Components](https://community.plotly.com/t/dynamic-controls-and-dynamic-output-components/5519). From that thread, we said: This means that you must generate callbacks for every unique set of input components that co…

---

<div class="post-metadata">

**Author:** ![kirk77](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kirk77](https://community.plotly.com/u/kirk77)\
**Post date:** [May 20, 2020, 7:06pm UTC](https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776/3 "2020-05-20T19:06:46Z")

</div>

Thank you. I am a newbie with Dash, but found it some helpful with limited programming knowledge. I read about it and tried to apply. In my case tables are already redered(lets say with same type and index 0…n). Now with pattern, in my callback I am not sure ho to get selected\_columns from that specific table. Any help is appreciated. Here is the code I am using, but i is returning null, so no column selected. For a single table this code is working fine as it is able to figure out the selected\_columns, but not sure how this can get selected columns across tables:

```auto
@app.callback(
    Output({'type': 'table-display', 'index': ALL}, 'style_data_conditional'),
    [Input({'type': 'table-display', 'index': ALL}, 'selected_columns')])
def update_styles(selected_columns):
    return [{
        'if': {'column_id': i},
        'background_color': '#D2F3FF'
    } for i in selected_columns]

```

And here is the error:

```auto
Error: Invalid argument `style_data_conditional` passed into DataTable with ID "{"index":2,"type":"table-display"}".

Expected an array.

Was supplied type `object`.

Value provided: 

{

  "if": {

    "column_id": []

  },

  "background_color": "#D2F3FF"

}

```

---

<div class="post-metadata">

**Author:** ![kirk77](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kirk77](https://community.plotly.com/u/kirk77)\
**Post date:** [May 22, 2020, 4:03am UTC](https://community.plotly.com/t/apply-same-callback-to-multiple-datatables/39776/4 "2020-05-22T04:03:59Z")

</div>

I am now able to figure out how. Again as the documentation suggested used a hidden DIV to store the original data of all the tables and using that with MATCH pattern.
