Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColumnsAutoSizeMode.FIT_CONTENTS not work in second tab of st.tabs #249

Open
spiritdncyer opened this issue Feb 20, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@spiritdncyer
Copy link

Using the columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS parameter in the AgGrid() call seems to work for all my tables on my first tab;
but in my second tab, it sometimes reduces the first few columns of my AgGrid to minimum width.
And if I use the suppressColumnVirtualisation:True option, it reduces all the columns to minimum width.
my first tab:
image
my second tab:
image
here is my code(streamlit==1.29.0, streamlit-aggrid==0.3.3):

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

data = {
    'System Name': ['System A', 'System B', 'System C', 'System D'],
    'Value 1': [10, 20, 30, 40],
    'Value 2': [1, 2, 3, 4],
    'Value 3': [10, 20, 30, 40],
    'Value 4': [1, 2, 3, 4],
    'Value 5': [10, 20, 30, 40],
    'Value 6': [1, 2, 3, 4],
    'Value 7': [10, 20, 30, 40],
    'Value 8': [1, 2, 3, 4],
    'Value 9': [10, 20, 30, 40],
    'Value 10': [1, 2, 3, 4],
    'Value 11': [10, 20, 30, 40],
    'Value 12': [1, 2, 3, 4],
    'Value 13': [10, 20, 30, 40],
    'Value 14': [1, 2, 3, 4],
    'Value 15': [10, 20, 30, 40],
    'Value 16': [1, 2, 3, 4],
}
df = pd.DataFrame(data)

# gridOptions1
gb1 = GridOptionsBuilder.from_dataframe(df)
gridOptions1 = gb1.build()

# gridOptions2
gb2 = GridOptionsBuilder.from_dataframe(df)
other_options = {'suppressColumnVirtualisation': True}
gb2.configure_grid_options(**other_options)
gridOptions2 = gb2.build()

tab1, tab2 = st.tabs(['tab1', 'tab2'])
with tab1:
    AgGrid(
        df,
        gridOptions=gridOptions1,
        columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
        key='1',
    )

with tab2:
    st.write('no FIT_CONTENTS and no suppressColumnVirtualisation')
    AgGrid(
        df,
        gridOptions=gridOptions1,
        key='2-1',
    )
    st.write('FIT_CONTENTS and no suppressColumnVirtualisation')
    AgGrid(
        df,
        gridOptions=gridOptions1,
        columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
        key='2-2',
    )
    st.write('FIT_CONTENTS and suppressColumnVirtualisation is true')
    AgGrid(
        df,
        gridOptions=gridOptions2,
        columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
        key='2-3',
    )
@PablocFonseca PablocFonseca added the bug Something isn't working label Mar 21, 2024
@PablocFonseca PablocFonseca self-assigned this Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants