I need to specify custom icons on my Ag-Grid (React) sidebar for custom panels. My toolpanels looks like this:
toolPanels: [
{
id: "actions",
labelDefault: "Actions",
labelKey: "actions",
iconKey: "entityActions",
toolPanel: "blotterActionsPanel",
toolPanelParams: {glEventHub: this.props.glEventHub}
},
{
id: "columns",
labelDefault: "Columns",
labelKey: "columns",
iconKey: "columns",
toolPanel: "agColumnsToolPanel"
},
{
id: "filters",
labelDefault: "Filters",
labelKey: "filters",
iconKey: "filter",
toolPanel: "agFiltersToolPanel"
}
]
for the 'actions' toolpanel I have iconKey 'entityActions', so my icons looks like this:
icons: {
entityActions: '<i class="fa fa-running" style="font-size: 12pt; color: darkgrey"/>',
}
That works for a font-awesome icon... but I don't want to use an FA icon. I need to use icons from BlueprintJS, which are SVG icons. BlueprintJS provides an tag which would be the easiest to use... but I've tried various things like this:
icons: {
entityActions: "<Icon icon='add'/>"
}
Which doesn't work... I can also get the raw SVG paths from BlueprintJS so I've tried:
entityActions: '<span><svg fill="black" height="16" width="16" viewBox={"0 0 16 16"}><path d=' + IconSvgPaths16.add[0] + '/></svg></span>',
and also I tried hard-coding the path... In all of these cases I just get a blank hole where I expect the icon to be. The Ag-Grid documentation (https://www.ag-grid.com/javascript-grid-icons/):
The icon can be any of the following: String: The string will be treated as html. Use to return just text, or HTML tags. Function: A function that returns either a String or a DOM node or element.
so, I tried a function... I cannot find an example of how to do this, but after a few hours of searching I came across examples that show it creating an element using document.createElement.. So I tried this:
entityActions: params => {
let icon = document.createElement('svg');
let path = document.createElement('path');
icon.setAttribute('fill', "black");
icon.setAttribute("height", "16");
icon.setAttribute("width", "16");
icon.setAttribute("viewBox", "0 0 16 16");
path.setAttribute("d", IconSvgPaths16.add[0]);
icon.appendChild(path);
return icon;
}
Still with no luck... How can I use a BlueprintJS Icon with Ag-Grid? This icon is actually customizable by the user so it would be good if I could use a function and pass in the icon name to use and have it return the appropriate one...
Thankyou, Troy.