Ag-Grid component with input support

I have reviewed my code, and it functions correctly, providing a complete tree structure using Aggrid. However, I require assistance in obtaining the value of a selected cell through mouse clicks. Could you please guide me on how to retrieve the selected cell value and provide the appropriate code? Thank you.

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

df=pd.DataFrame([{“orgHierarchy”: ‘A’, “jobTitle”: “CEO”, “employmentType”: “Permanent” },
{ “orgHierarchy”: ‘A/B’, “jobTitle”: “VP”, “employmentType”: “Permanent” },
{ “orgHierarchy”: ‘A/B/A’, “jobTitle”: “VP”, “employmentType”: “Permanent” },
{ “orgHierarchy”: ‘A/C’, “jobTitle”: “Manager”, “employmentType”: “Permanent” }])
st.write(df)
gb = GridOptionsBuilder.from_dataframe(df)
gridOptions = gb.build()

gridOptions[“columnDefs”]= [
{ “field”: ‘jobTitle’ },
{ “field”: ‘employmentType’ },
]
gridOptions[“defaultColDef”]={
“flex”: 1,
},
gridOptions[“autoGroupColumnDef”]= {
“headerName”: ‘Organisation Hierarchy’,
“minWidth”: 300,
“cellRendererParams”: {
“suppressCount”: True,
},
},

gridOptions[“treeData”]=True
gridOptions[“animateRows”]=True
gridOptions[“groupDefaultExpanded”]= -1
gridOptions[“getDataPath”]=JsCode(“”" function(data){
return data.orgHierarchy.split(“/”);
}“”").js_code

r = AgGrid(
df,
gridOptions=gridOptions,
height=500,
allow_unsafe_jscode=True,
enable_enterprise_modules=True,
filter=True,
#update_mode=GridUpdateMode.SELECTION_CHANGED,
theme=“material”,
tree_data=True
)

st.write(r)

@PablocFonseca,

Thanks for streamlit-agGrid - ag-grid is a great tool.

I’d like to have either an action button on the row or add a menu button in the context menu that when clicked it will call a python function for example it will open a streamlit dialog.
is that possible, I was trying to add it to the context menu but it has no reference to the function…
any ideas?

@larryb64 I understand it’s been a while since this post but just curious, did you find a way to pull the virtual column data from the grid response? Since the virtual columns are calculated in the browser they are not being pulled into the response but I’m trying to find a way to capture the values from the response to use the data else where.

@PablocFonseca Thanks for creating st_aggrid, it’s an awesome component.

Is there a way to pull the virtual column values in the grid_response or any other way to capture these values instead of having to redo the wole calculation in python? I’m currently rendering the virtual column values based on user input into a different column and not able to use these calculated values else where other than in aggrid. I want to render some charts and also use these values for generating a different data frame and not being able to capture these values is making it difficult to do any of the above.