Aggrid - Unselect all Rows

Hello, I would like to add a button in my Streamlit project to clear all the rows selected in an Aggrid Table with checkbox. Is there a way of doing it ? I tried various things (i.e. api.deselectAll()) but could not make it). Thanks for your help.

1 Like

hi @Gegeh , you can add a checkbox to the column header during the grid configuration:

With this checkbox, you can de/select all rows.



Thank you very much for your prompt answer. Highly appreciated.

1 Like

Hi Shawn, I’m appreciate your last post, very useful. May I ask if it possible to get the headerchecbox already selected when Streamlit app is launched.


Hi @Philippe_Franco , there are probably 2 ways to do this, both of which I have not tried out.

  1. Pre-selection:
    a. Find out the number of dataframe rows that feed into your aggrid (using a command such as totrows = df.shape[0])
    b. Configure your aggrid initially with
    gb.configure_selection(‘multiple’, pre_selected_rows=[1, totrows])

  2. I suppose you could also use the aggrid API, which I have not attempted at all (because I never had the need to)



Hi all,

Has anyone successfully used the aggrid API’s deselectAll() function for the Streamlit-aggrid component? In case you can share an example :slight_smile: Thanks a lot.

Hello Shawn, Thank you for your help!

Hi @Shawn_Pereira ,
I am trying to set this for the first column in my table -

gb.configure_column("year", headerCheckboxSelection = True)

I am getting the following error -

TypeError: list indices must be integers or slices, not str

If I understand correctly, I am supposed to pass the column name. Would you have some idea about what is going wrong?

The table is functioning fine without this line and I am able to select individual rows.

This is the full code in case it helps -

gb = GridOptionsBuilder.from_dataframe(df_country_rank_nb_customers)
gb.configure_pagination(paginationAutoPageSize=True)  # Add pagination
gb.configure_side_bar()  # Add a sidebar
gb.configure_selection('multiple', use_checkbox=True) #Enable multi-row selection
gridOptions =
gb.configure_column("year", headerCheckboxSelection = True)

grid_response = AgGrid(
    theme="blue",  # Add theme color to the table Available options: ['streamlit', 'light', 'dark', 'blue', 'fresh', 'material']

data = grid_response["data"]
selected = grid_response["selected_rows"]
df1 = pd.DataFrame(selected)  # Pass the selected rows to a new dataframe df1


Hi @mjo , I don’t have my laptop with me, but you can try out these two things:

  1. Move the line:
    gb.configure_column(“year”, headerCheckboxSelection = True)

above the line:
gridOptions =

in your code and check. If that doesn’t work:

  1. Please check if field name (year) exactly matches your df field name.


1 Like

Hi @Shawn_Pereira ,
Thanks for your quick reply. Option 1 suggested by you worked :slight_smile: Thanks!