Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement editable dataframe to manage dataframe editor component #65

Closed
FabienArcellier opened this issue Jun 28, 2024 · 0 comments
Closed
Assignees
Labels
enhancement New feature or request in review The PR is open in review

Comments

@FabienArcellier
Copy link
Owner

FabienArcellier commented Jun 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in review The PR is open in review
Projects
None yet
Development

No branches or pull requests

1 participant