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