import writer as wf
def on_record_add(state, payload):
payload.record['sales'] = 0 # default value inside the dataframe
state['df'].record_add(payload)
def on_record_change(state, payload):
state['df'].record_update(payload)
def on_record_action(state, payload):
"""
This event corresponds to a quick action in the drop-down menu to the left of the dataframe.
"""
if payload.action == 'remove':
state['df'].record_remove(payload)
if payload.action == 'important':
state['df'].record(payload.id).update('flag', True) # update the column flag of the dataframe to true, trigger une mutation record_update
if payload.action == 'open':
state['record'] = state['df'].record(payload.id)
def on_record_select(state, payload):
state['df_selected_record'] = payload['selected']
# trigger on button outside the dataframe editor
def on_save_click(state, payload):
state['df'].df.to_csv('file.csv')
initial_state = ss.init_state({
"df": wf.EditableDataframe(
df
)
})
# snippets
state['df'].df # get the real dataframe datastructure
state['df'].df = df # set a new dataframe, send the entire dataframe
state['df'].record_update(payload) # update a record using frontend payload
state['df'].record_remove(payload) # remove a record using frontend payload
state['df'].record_add(payload) # add a new record using frontend payload
more in #63