Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions st_aggrid/AgGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def AgGrid(
columns_state=None,
theme: str | StAggridTheme = "streamlit",
custom_css=None,
links: typing.List[str] = None,
key: typing.Any = None,
update_on=[],
callback=None,
Expand Down Expand Up @@ -281,6 +282,9 @@ def AgGrid(
Custom CSS rules to be added to the component's iframe.
Defaults to None.

links : typing.List[str], optional
List of URLs to external stylesheets (e.g. FontAwesome, Material Icons) to be loaded in the component.

key : typing.Any, optional
Streamlit's key argument. Check Streamlit's documentation.
Defaults to None.
Expand Down Expand Up @@ -376,6 +380,7 @@ def AgGrid(
try_to_convert_back_to_original_types = False

custom_css = custom_css or dict()
links = links or []

if height == None:
gridOptions["domLayout"] = "autoHeight"
Expand Down Expand Up @@ -425,6 +430,7 @@ def _inner_callback():
columns_state=columns_state,
theme=themeObj,
custom_css=custom_css,
links=links,
update_on=update_on,
manual_update=manual_update,
key=key,
Expand Down
22 changes: 21 additions & 1 deletion st_aggrid/frontend/src/AgGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ import ManualUpdateButton from "./components/ManualUpdateButton"
import ManualDownloadButton from "./components/ManualDownloadButton"
import QuickSearch from "./components/QuickSearch"

interface CustomStylesheetProps {
url: string;
}

function CustomStylesheet({ url }: CustomStylesheetProps) {
React.useEffect(() => {
const link = document.createElement('link');
link.href = url;
link.rel = 'stylesheet';
document.head.appendChild(link);
return () => {
document.head.removeChild(link);
};
}, [url]);
return null;
}

import {
getCSS,
addCustomCSS,
Expand Down Expand Up @@ -354,6 +371,9 @@ class AgGrid extends React.Component<ComponentProps, State> {
ref={this.gridContainerRef}
style={this.defineContainerHeight()}
>
{this.props.args.links?.map((url: string) => (
<CustomStylesheet key={url} url={url} />
))}
<GridToolBar
showManualUpdateButton={manualUpdate}
enabled={this.props.args.show_toolbar ?? true}
Expand All @@ -379,4 +399,4 @@ class AgGrid extends React.Component<ComponentProps, State> {
}
}

export default withStreamlitConnection(AgGrid)
export default withStreamlitConnection(AgGrid)