# Create a GridOptionsBuilder
gb = GridOptionsBuilder.from_dataframe(df_unselected)
# Configure grid options
gb.configure_pagination(enabled=True)
gb.configure_default_column(editable=True, groupable=True)
# Configure selection mode and use checkboxes
gb.configure_selection(selection_mode='multiple', use_checkbox=True)
gb.configure_default_column(cellStyle={'color': 'black', 'font-size': '12px'}, suppressMenu=True, wrapHeaderText=True, autoHeaderHeight=True)
custom_css = {".ag-header-cell-text": {"font-size": "10px", 'text-overflow': 'revert;', 'font-weight': 700},
".ag-theme-streamlit": {'transform': "scale(0.8)", "transform-origin": '0 0'}}
# Build grid options
gridoptions = gb.build()
# Create AgGrid with specified options
grid_table = AgGrid(df_unselected, gridOptions=gridoptions,
update_mode=GridUpdateMode.VALUE_CHANGED,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
theme=AgGridTheme.BALHAM,
#width='100%',
#height=1000,
allow_unsafe_jscode=True)
# Retrieve selected rows as a list of dictionaries
selected_rows = grid_table["selected_rows"]
# Extract indices from the list of dictionaries
selected_indices = [row["index"] for row in selected_rows]
# Filter original DataFrame based on selected indices
df_selected = df_unselected.loc[selected_indices]
# # Display output
# st.subheader("Selected QC Runs")
# df_selected = pd.DataFrame(selected_indices)
# st.dataframe(df_selected)
# Display output
st.subheader("Selected QC Runs")
st.write(df_selected)
Python version is 3.9 and streamlit version is 1.12