@AIMPED
I have one more question about this. Is there a way to implement this in a DataTable. I have multiple DataTables with dropdown entries as well. I have created a function to create the tables, but now I am trying to tie it to the callback. Here is the function that creates my DataTable.
#Draws a table with a Title, df=data, dd=list of dropdown columns
def drawTable(Title,df,dd):
col=[] #initialize column list
opt={} #initialize drop down options
#Create columns and the associated dropdown options
for i in df.columns:
if i in dd: #dd stands for dropdown so if column is in the dropdown list execute this statement
#ddc stands for dropdown column
ddc={"name": [Title,i], "id": i, 'presentation':'dropdown'}
col.append(ddc)
#Create Dropdown options (ddo)
ddo={i:{'options':[{'label':'Add New','value':'Add New'}]+[{'label':o, 'value':o} for o in df[i].unique()]}}
opt.update(ddo)
else:
c={"name": [Title,i], "id": i}
col.append(c)
return html.Div([
dash_table.DataTable(
id={'type': 'tbl', 'index': Title},
data=df.to_dict('records'),
columns=col,
editable=True,
row_deletable=True,
dropdown=opt,
style_data={'color': 'black','backgroundColor': '#CDE5E8'},
style_data_conditional=[{'if': {'row_index': 'odd'},'backgroundColor': 'rgb(232, 242, 244)'}],
style_header={'backgroundColor': 'rgb(46, 179, 190)','color': 'white','fontWeight': 'bold','textAlign': 'center'},
merge_duplicate_headers=True,
),
dbc.Button('Add Row', id={'type': 'btn', 'index': Title}, n_clicks=0,style= {'backgroundColor': 'rgb(46, 179, 190'}, class_name='mt-0 mb-1')
])