var dagcomponentfunc = window.dashAgGridComponentFunction = window.dashAgGridComponentFunction || {};
dagcomponentfuncs.CustomTooltip = function (props) {
info = []
if (props.data){
if (props.value == 'measure')
info = [
React.createElement('div', {}, props.data.measure)
];
else if (props.value == 'initiative')
info = [
React.createElement('div', {}, props.data.initiative)
];
}
return React.createElement(
'div',
{
style: {
border: '0pt',
backgroundColor: props.color || 'grey',
padding: 10,
},
},
info
);
};
Hello @Vaishali,
Iâm not sure what isnât working, the value would determine the info.
You could use params.column.colId
and check the field matches. I think it would exist in this params data set.
Hi @Vaishali,
Yes, agree with @jinnyzor
props.value
gets you the value of the cell you are hovering not the column name.
props.column.colId
should works as you are trying to compare to âmeasureâ/âinitiativeâ which seem to be the field
names, thus colId
should be the same (if you didnât set a customcolId
in columnDefs
)
Or you can use the headers if you set headerName
which you can access with props.colDef.headerName
You can also pass a different tooltipComponent
to each columnDef
:
js code where they handle this
{
headerName: 'Athlete Col 1',
field: 'athlete',
minWidth: 150,
tooltipField: 'athlete',
},
{
headerName: 'Athlete Col 2',
field: 'athlete',
minWidth: 150,
tooltipComponent: CustomTooltip,
tooltipValueGetter: toolTipValueGetter,
},
What was your final Solution?
I have been trying to apply:
if (props.colDef.headerName == âStock Tickerâ)
info = [
React.createElement(âh4â, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.price),
];
else if (props.colDef.headerName == âCompanyâ)
info = [
React.createElement(âh5â, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.price),
but it doesnât seem to work
Hello @Mr.King,
Iâd use props.column.colId
instead, that way it will match what your rowData
column.
Also, make sure you are wrapping your returns like this:
if (props.column.colId == 'ticker') {
info = [
React.createElement(âh4â, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.price),
];
}
else if (props.column.colId == 'company') {
info = [
React.createElement(âh5â, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.price),
]
}
I finally got it to work.
FYI in your code at the top, there is an âsâ missing from the end of the first line.
Donât ask how long it took me to figure that out.
var dagcomponentfuncs = window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {};
dagcomponentfuncs.CustomTooltip = function (props) {
info =
console.log(props)
if (props.data){
if (props.colDef.headerName == âStock Tickerâ)
info = [
React.createElement(âh4â, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.price),
];
else if (props.colDef.headerName == âCompanyâ)
info = [
React.createElement(âh5â, {}, props.data.company),
React.createElement(âdivâ, {}, props.data.ticker),
React.createElement(âdivâ, {}, props.data.price),
];
}
return React.createElement(
'div',
{
style: {
border: '2pt solid white',
backgroundColor: props.color || 'grey',
padding: 10,
},
},
info
);
};
with the scipt:
data = {
âtickerâ: [âAAPLâ, âMSFTâ, âAMZNâ, âGOOGLâ],
âcompanyâ: [âAppleâ, âMicrosoftâ, âAmazonâ, âAlphabetâ],
âpriceâ: [154.99, 268.65, 100.47, 96.75],
}
df = pd.DataFrame(data)
columnDefs = [
{
âheaderNameâ: âStock Tickerâ,
âfieldâ: âtickerâ,
âtooltipFieldâ: âtickerâ,
âtooltipComponentParamsâ: { âcolorâ: â#d8f0d3â },
},
{
"headerName": "Company",
"field": "company",
"tooltipField": 'company',
"tooltipComponentParams": { "color": '#d8f0d3' },
},
{
"headerName": "Last Close Price",
"field": "price",
"valueFormatter": {"function": """d3.format("($,.2f")(params.value)"""},
"editable": True,
},
]
grid = dag.AgGrid(
id=âtooltip-simple-exampleâ,
columnDefs=columnDefs,
rowData=df.to_dict(ârecordsâ),
columnSize=âsizeToFitâ,
defaultColDef={âeditableâ: False, âtooltipComponentâ: âCustomTooltipâ},
dashGridOptions={âtooltipShowDelayâ: 100}
)