Without giving the entire code everything works currently with adding and deleting a row. However, now I’m currently trying to implement a multi-option “add-row” function. So that the user can initialize through a slider but then if needed manually click the add row button. I’m not sure if this actually “necessary” or just an overkill and redundant user options for the same function. Please advise or share what you’ve done for something like this. thanks.
html.Div(children=[
html.Label('# of Wells on Pad', style={'color':colors['text']}),
dcc.Slider(
id='well_slider',
min=0,
max=12,
step=1,
marks={i: f' {i}' if i == 1 else str(i) for i in range(13)},
value=0,
),
], style={'padding': 10, 'flex': 1, 'background-color':colors['background'],'margin':20})
], style={'display': 'flex', 'flex-direction': 'row',}),
# html.
html.Div(children=[
dash_table.DataTable(
id='projection_table',
columns=[{
'name': i,
'id': i,
} for i in table_outputs],
style_cell={'text-align':'center'},
data=[
{'column-{}'.format(i): (j + (i-1)*5) for i in range(1, 5)}
for j in range(5)
],
editable=True,
fill_width=True,
row_deletable=True,
export_format='xlsx',
export_headers='display',
style_table={'overflowX':'scroll', 'background-color':'white'}
),
html.Button('Add Row', id='editing-rows-button', n_clicks=0, style={'margin':5}),
html.Div(id='testingSlider', style={"color":colors['text']})
],style={'margin':10})
],style={'background-color':colors['document'], 'height':'100vh','width':'100'}
)
#-------------------------------------------------------------------------------------------
# Call back Table
# Last working on creating a callback state to add a row
@app.callback(
Output('projection_table', 'data'),
Input('editing-rows-button', 'n_clicks'),
Input('well_slider', 'value'),
State('projection_table', 'data'),
State('projection_table', 'columns'),
prevent_initial_call=True
)
def add_row(n_clicks, rows, table_outputs):
triggered_id = callback_context.triggered[0]['prop_id']
if 'editing-rows-button' == triggered_id:
if n_clicks > 0:
rows.append({c['id']: '' for c in table_outputs})
return rows
elif 'well_slider'== triggered_id:
return rows