Creating a custom aggregate function for a pivot table in ag-grid (streamlit-aggrid)?

I am trying to perform a ‘% of Grand Total’ & ‘% of Parent Total’ for my pivot table using streamlit-aggrid. Can someone suggest how I could achieve this? Do I need to use JsCode? If so, what could be the code for this?