To upload files, please first save the app
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridOptionsBuilder
# Load your dataset
df = pd.read_json("https://www.ag-grid.com/example-assets/olympic-winners.json")
# Configure grid options
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_default_column(
groupable=True,
value=True,
enableRowGroup=True,
aggFunc='sum'
)
# Possible option are
# configure_default_column
# configure_auto_height
# configure_grid_options
# configure_columns
# configure_column
# configure_side_bar
# configure_selection
# configure_pagination
# configure_first_column_as_index
# Customize specific column behaviors
gb.configure_column('country', header_name="Home Country")
gb.configure_pagination(enabled=True, paginationPageSize=5)
gb.configure_selection(selection_mode="multiple", use_checkbox=True)
gb.configure_side_bar(filters_panel=True, defaultToolPanel='filters')
# Build the final option object
grid_options = gb.build()
# Render AgGrid
AgGrid(
df,
gridOptions=grid_options,
height=400,
width='100%',
allow_unsafe_jscode=True
)
# Create sample data
df = pd.DataFrame({
'name': ['John', 'Jane', 'Bob'],
'age': [25, 30, 35],
'salary': [50000, 60000, 75000]
})
# Initialize GridOptionsBuilder
gb = GridOptionsBuilder.from_dataframe(df)
# Get all public methods
methods = [attr for attr in dir(GridOptionsBuilder)
if not attr.startswith('_') and callable(getattr(GridOptionsBuilder, attr))]
st.markdown("## GridOptionsBuilder Available Methods")
st.markdown("""
This interactive demo shows all available configuration methods in GridOptionsBuilder.
Each method listing includes its actual implementation details.
""")
# Create tabs for different views
tab1, tab2 = st.tabs(["📖 Method Details", "🔧 Interactive Grid"])
with tab1:
# Display method details
for method_name in methods:
with st.expander(f"📍 {method_name}"):
# Get and display the actual method implementation
method = gb.__getattribute__(method_name)
st.write(method)
# Show example code for common methods
if method_name in ['configure_column', 'configure_selection', 'configure_pagination']:
st.markdown("**Example Usage:**")
if method_name == 'configure_column':
example = '''
gb.configure_column("price",
editable=True,
type=["numericColumn"],
valueFormatter="x.toLocaleString()"
)
'''
elif method_name == 'configure_selection':
example = '''
gb.configure_selection(
selection_mode="multiple",
use_checkbox=True,
groupSelectsChildren=True
)
'''
elif method_name == 'configure_pagination':
example = '''
gb.configure_pagination(
enabled=True,
paginationAutoPageSize=True,
paginationPageSize=10
)
'''
st.code(example, language="python")
with tab2:
# Interactive grid demo
st.markdown("### Configure Grid Options")
# Selection options
st.markdown("#### Selection Options")
selection_mode = st.selectbox("Selection Mode", ["single", "multiple", "disabled"])
use_checkbox = st.checkbox("Use Checkboxes", value=False)
# Pagination options
st.markdown("#### Pagination Options")
enable_pagination = st.checkbox("Enable Pagination", value=False)
# Configure the grid based on selections
if selection_mode != "disabled":
gb.configure_selection(selection_mode=selection_mode, use_checkbox=use_checkbox)
if enable_pagination:
page_size = st.slider("Page Size", min_value=2, max_value=10, value=5)
gb.configure_pagination(enabled=True, paginationPageSize=page_size)
# Column options
st.markdown("#### Column Options")
sortable = st.checkbox("Sortable Columns", value=True)
filterable = st.checkbox("Filterable Columns", value=True)
gb.configure_default_column(
sortable=sortable,
filterable=filterable
)
# Build and display the grid
grid_options = gb.build()
AgGrid(df, grid_options)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?