✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Datatable editable for only 1 column

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

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 :slight_smile:

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:

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

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

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

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:

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%'})```