# Datatable editable for only 1 column

**URL:** <https://community.plotly.com/t/datatable-editable-for-only-1-column/46491>\
**Category:** Dash Python\
**Created:** [October 26, 2020, 2:01pm UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491 "2020-10-26T14:01:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasVerhalen](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@JonasVerhalen](https://community.plotly.com/u/JonasVerhalen)\
**Post date:** [October 26, 2020, 2:01pm UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491/1 "2020-10-26T14:01:11Z")

</div>

I have a function that returns me a data table, I simply pass the df and it returns me the dataframe, however I want to be able to give my function the argument to make only 1 column editable

Editable= True is a solution but this makes the whole dataframe editable which is not something I want

```auto
return dash_table.DataTable(
                    id=table_id,
                    sort_action='native',
                    columns=[{"name": i, "id": i} for i in df.columns],
                    data=df.to_dict('records'),
                    style_table={'width':'98%'})

```

Thank you in advance 🙂

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [October 26, 2020, 2:42pm UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491/2 "2020-10-26T14:42:12Z")

</div>

Hi @JonasVerhalen

You could make the function take the df and the id of the editable column… in the example below I called it `editable_col`  
Then update the columns= to look like this:

```auto
columns=[{"name": i, "id": i} if i != editable_col else {"name": i, "id": i, "editable": True} for i in df.columns]

```

---

<div class="post-metadata">

**Author:** ![JonasVerhalen](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@JonasVerhalen](https://community.plotly.com/u/JonasVerhalen)\
**Post date:** [October 26, 2020, 3:06pm UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491/3 "2020-10-26T15:06:31Z")

</div>

Am I doing something wrong cus for me this still seems to make the whole table editable

````auto
def CreateTableEditable(df,table_id,editable_col):
    return dash_table.DataTable(
                    id=table_id,
                    sort_action='native',
                    editable=True,
                    columns=[{"name": i, "id": i} if i != editable_col else {"name": i, "id": i, "editable": True} for i in df.columns],
                    data=df.to_dict('records'),
                    style_table={'width':'98%'})```

Me calling the function:

````

def getSettings():

```
df =Logging(database='exchanges').ReadQueryPandas('SELECT * FROM Markets')

layout_settings_body = html.Div([

    dashcumps.Navbar(),

    dcc.Tabs(id='tabs-settings', value='tab-Markets', children=[

                           dcc.Tab(label='Markets', value='tab-Markets'),

                            ]),

                       html.Div(id='tabs-settings-content',children=[dashcumps.CreateTableEditable(df=df,table_id='a',editable_col='tradingEnabled')])

])

return layout_settings_body

```

```auto

```

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [October 26, 2020, 3:20pm UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491/4 "2020-10-26T15:20:44Z")

</div>

You can set the editable property at either (or both) the table level or the column level. The column level overrides the table level. So you can set edtiable =False for the table - or take it out since False is the default.

Try this:

````auto
return dash_table.DataTable(
                    id=table_id,
                    sort_action='native',
                    editable=False,
                    columns=[{"name": i, "id": i} if i != editable_col else {"name": i, "id": i, "editable": True} for i in df.columns],
                    data=df.to_dict('records'),
                    style_table={'width':'98%'})```

````

---

<div class="post-metadata">

**Author:** ![beginof](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/beginof/32/19813_2.png) [@beginof](https://community.plotly.com/u/beginof)\
**Post date:** [November 1, 2022, 3:59am UTC](https://community.plotly.com/t/datatable-editable-for-only-1-column/46491/5 "2022-11-01T03:59:27Z")

</div>

HI,

Can you advise how can I make the same in the callback?

```
dash_table.DataTable(id='tabletrn', 
                                columns=[
                                    {'name': 'Status', "id": 'header'},
                                    {'name': 'Activity Date', "id": 'info'},
                                    {'name': 'Reference ID', "id": ''},

                                        ],
                            editable=False,    
                            style_cell={'textAlign': 'left'},
                            
                              ),

@app.callback(
    Output('tabletrn', 'data'), 
    Input('trnid', 'value')
    )

def update_table(selection):
    if len (selection) == 0:
        return dash.no_update

    else:  
        dff = df[df['Transaction ID'] == selection]  

    
        transpose = dff.melt(id_vars = ['refer']
                                               ,var_name = ['header']
                                               ,value_name = 'info')
    
        columns = info[['header','info']]

        data= columns.to_dict('records')

   
        return data

```
