Delete all rows in a DataTable

Hello,

is it possible to delete all rows all in once in a DataTable?
I tried to make a button for that. But it doesn´t work.
Can someone help me? Thanks

Hey Pat,

You can delete all the rows in the DataTable with a callback that outputs to the data property of the table. When the delete button was pressed, the callback would just have to return an empty dataframe. For example, if the id of the DataTable was ‘table’ and the id of the button was ‘delete-button’ then the callback should look like this:

@app.callback(
    Output('table', 'data'),
    [Input('delete-button', 'n_clicks')]
)
def delete_table_data(n_clicks):
    if n_clicks == 0:
        raise dash.exceptions.PreventUpdate()
    data = pd.DataFrame().to_dict('records')  #empty dataframe
    return data
1 Like

Or you could simply return which is an empty list, saving yourself the need for pandas

Thank you. It works :smiley: You are my hero