Dynamic vertical resize of the Ag-Grid table

Hi @PablocFonseca ,
I am new to streamlit-aggrid. I have a CSV file which I am loading into a pandas dataframe and creating an AgGrid table on top of it with filters for all the columns present in the dataframe.

My requirement is I want to dynamically resize the AgGrid table size on basis on my filter’s selections as I want to avoid the empty space it is creating at the below in case of small no of rows.

FYI, my filtered data can have 1 as record as well.

Therefore I want to calculate the filter table size on runtime and decide the height of the AgGrid table.

*Can you please help me and provide any direction on how I can achieve this. *
Below is my code which I tried:

import streamlit as st
import pandas as pd
from st_aggrid import AgGrid,GridOptionsBuilder, GridUpdateMode,ColumnsAutoSizeMode

data = {‘database’: [‘bidh_ld_ais_wrk’,‘bidh_ld_ais_wrk’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’,‘bidhr_ld_ais_ccp’],
‘tablename’: [‘demandoverall’,‘purchaseforecasttable’,‘axis_d_product_cat’,‘cq_axis_product_fidc’,‘cq_axis_productc’,‘cq_axis_seg_carrierc’,‘cq_axis_seg_dauditc’,‘cq_axis_seg_snc’,‘cq_axis_seg_stat_histc’,‘cq_axis_segmentc’,‘cq_axis_taskc’,‘cq_daily_sales’,‘dimensionansweredskill’,‘dimensionbauhours’,‘dimensionconrepeatcalldelaydays’,‘dimensioncustomerexception’,‘factactivitiesclosed’,‘fcr_repeat_calls’,‘iex_d_exception’],
‘duplicate_tables_list’: [‘demandprep,demandprepfinal’,‘purchaseforecasttable_sapibp’,‘cq_product_category’,‘cq_axis_product_fidi’,‘cq_axis_producth,cq_axis_producti’,‘cq_axis_seg_carrieri’,‘cq_axis_seg_dauditi’,‘cq_axis_seg_snh,cq_axis_seg_sni’,‘cq_axis_seg_stat_histi’,‘cq_axis_segmento’,‘cq_axis_taski’,‘cq_daily_sales_temp’,‘temp_dimensionansweredskill’,‘table_name’,‘dimensionrepeatcalldelaydays’,‘dimensioncustomerexceptioncbr’,‘factactivitiescloseddetail’,‘fcr_repeat_calls_2,fcr_repeat_calls_40’,‘iex_d_exception1’]}

@st.cache_data
def convert_df(df):
# IMPORTANT: Cache the conversion to prevent computation on every rerun
return df.to_csv(index=False).encode(‘utf-8’)

max_height = 400
df = pd.DataFrame(data)
gridOptions = {
“columnDefs”: [
{
“field”: “database”,
“filter”: “agTextColumnFilter”,
“filterParams”: {
“buttons”: [“reset”, “apply”],
},
“minWidth”: 150,
},
{
“field”: “tablename”,
“filter”: “agTextColumnFilter”,
“filterParams”: {
“buttons”: [“reset”, “apply”],
},
“minWidth”: 150,
},
{
“field”: “duplicate_tables_list”,
“filter”: “agTextColumnFilter”,
“filterParams”: {
“buttons”: [“reset”, “apply”],
},
“minWidth”: 150,
},
]
}

Display the table using streamlit-aggrid

AgGrid(df,
gridOptions=gridOptions,
update_mode=GridUpdateMode.SELECTION_CHANGED | GridUpdateMode.VALUE_CHANGED | GridUpdateMode.FILTERING_CHANGED,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
fit_columns_on_grid_load = True,
height=min(max_height, (1 + len(df.index)) * 29),
# update_on=,
enable_enterprise_modules=True,
allow_unsafe_jscode=True
# key=“fix3”,
)

aggrid_dynamic_vertical_sizing-min