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)