Making only some columns editable on streamlit-aggrid?

I’m new to streamlit-aggrid. I have a CSV file I want to load to a dynamic table and allow editions to only some of the columns. I saw this example:

import streamlit as st
import pandas as pd
from st_aggrid import AgGrid

df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6]})
grid_return = AgGrid(df, editable=True)
new_df = grid_return['data']

So I’ve followed it, but let’s say that instead of editable=True, that allows both col1 and col2 values to be modified, I want to allow modifications on one of them (not important which one).

How can I do that please? Thanks!

I tried to pass a columns subset into the editable args but it is only accepting boolean values.

Hi @jay1, you’ll have to do something like this:

Between your 4th & 5th lines, you will need to insert statements to configure your grid options, like below:

gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_column(“col1”, editable=True)
gb.configure_column(“col2”, editable=False)
gridOptions = gb.build()

grid_return = AgGrid(df,
gridOptions=gridOptions)

Also, you will need to modify your 3rd line as below:

from st_aggrid import GridOptionsBuilder, AgGrid

Cheers

Hi @Shawn_Pereira,

how I can track the rows or entries which is changed on the editable table with AgGrid ?

Hi @secret, I had written a similar code (Ag-Grid component with input support - #236 by Shawn_Pereira) which you can refer to. However, this was for aggrid version 0.2.3. I currently use version 0.3.3. Between then and now there are changes in syntax. If you plan to test the code from the link and are using 0.3.3 then you need to make the following changes:

  1. delete the line theme="streamlit",
  2. Lines similar to dta['data']['Amt'][i] would now be dta['data'][i]['Amt']

Cheers

hi @Shawn_Pereira, i Used ag-Grid in Streamlit to create a 2x10 DataFrame, where the first column has random values between 0 and 1, and the second column has random values. i want to add the condition such that if the value of the row in the first column is 1, then the value of the corresponding row in the second column can be edited otherwise it cannot be edited. help me thank you very much.