# Using the tooltip component

**URL:** <https://discuss.streamlit.io/t/using-the-tooltip-component/36616>\
**Category:** Custom Components\
**Created:** [January 25, 2023, 12:25pm UTC](https://discuss.streamlit.io/t/using-the-tooltip-component/36616 "2023-01-25T12:25:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nauane\_Linhares](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nauane_linhares/32/22246_2.png) [@Nauane\_Linhares](https://discuss.streamlit.io/u/Nauane_Linhares)\
**Post date:** [January 25, 2023, 12:25pm UTC](https://discuss.streamlit.io/t/using-the-tooltip-component/36616/1 "2023-01-25T12:25:56Z")

</div>

I’m creating a screen for project management. For that, I’m trying to use the tooltip component of aggrid. In this case, there would be a table with the tasks and I would like that when I hover over a certain one, it will show a pop-up with some information about that task.

I tried to do what has been described [here](https://ag-grid.com/javascript-data-grid/component-tooltip/), I tried to make some adaptations but nothing worked

My code so far has been this, but so far nothing has worked, when I hover over one of the columns it only shows the name of that cell.

O código base que eu estou tentando está conforme abaixo:

gb = ag.GridOptionsBuilder.from\_dataframe(df)  
gridOptions = gb.build()  
customTooltip = ag.JsCode(“”"class CustomTooltip {  
init(params) {  
this.eGui = document.createElement(‘div’);  
this.color = ‘white’;  
this.data = params.api.getDisplayedRowAtIndex(params.rowIndex).data;

```
                this.eGui.classList.add('custom-tooltip');
                //@ts-ignore
                this.eGui.style['background-color'] = color;
                this.eGui.innerHTML = `
                        <p>
                            <span class"id">${this.data.task_id}</span>
                        </p>
                        <p>
                            <span>Name: </span>
                            ${this.data.task_name}
                        </p>
                    `;
            }

            getGui() {
                return this.eGui;
            }
            }""")
        gridOptions["tooltipShowDelay"] = 0
        gridOptions["tooltipHideDelay"] = 2000

        columnsDefs = list(map(lambda x: {"field": x}, columns))
        columnsDefs = [({"field": column["field"], "cellRenderer":self.set_checkbox()}) if column["field"] in list(
            df.select_dtypes("bool").columns) else ({"field": column["field"], "tooltipField": column["field"]}) for column in columnsDefs]
        gridOptions["columnDefs"] = columnsDefs
        gridOptions["tooltipComponent"] = customTooltip

```

---

<div class="post-metadata">

**Author:** ![Shawn\_Pereira](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shawn_pereira/32/44502_2.png) [@Shawn\_Pereira](https://discuss.streamlit.io/u/Shawn_Pereira)\
**Post date:** [January 25, 2023, 1:14pm UTC](https://discuss.streamlit.io/t/using-the-tooltip-component/36616/2 "2023-01-25T13:14:46Z")

</div>

Hi @Nauane_Linhares, see if this works for you:

> [@\[Aggrid\] Displaying cell information when the mouse is over a cell on an Aggrid table](https://discuss.streamlit.io/t/aggrid-displaying-cell-information-when-the-mouse-is-over-a-cell-on-an-aggrid-table/24813/2):
>
> Hi @AlexWeeM, Try this code if you have not yet found a solution: import streamlit as st from st\_aggrid import JsCode, AgGrid, GridOptionsBuilder from st\_aggrid.shared import GridUpdateMode df=pd.DataFrame({ "Name": ['Erica', 'Rogers', 'Malcolm', 'Barrett'], "Age": [43, 35, 57, 29]}) tooltipjs = JsCode(""" function(params) { return '\<span title="' + params.value + '"\>'+params.value+'\</span\>'; }; """) # if using with cellRenderer gridOptions = GridOptionsBuilder.from\_dataframe(df) gridOptio…

Cheers

---

<div class="post-metadata">

**Author:** ![Nauane\_Linhares](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nauane_linhares/32/22246_2.png) [@Nauane\_Linhares](https://discuss.streamlit.io/u/Nauane_Linhares)\
**Post date:** [January 25, 2023, 2:23pm UTC](https://discuss.streamlit.io/t/using-the-tooltip-component/36616/3 "2023-01-25T14:23:29Z")

</div>

I was able to do what I wanted by putting the line that defines columnsdef like this:

```auto
 columnsDefs = [({"field": column["field"], "cellRenderer":self.set_checkbox()}) if column["field"] in list(
                df.select_dtypes("bool").columns) else ({"field": column["field"], "tooltipField": column["field"], "tooltipComponent": self.tooltip_component()}) for column in columnsDefs]

```

Where the tooltip\_component function is as below:

```auto
def tooltip_component(self):
        tooltip = ag.JsCode("""class CustomTooltip {
                init(params) {
                    const eGui = (this.eGui = document.createElement('div'));
                    const color = params.color || 'white';
                    const data = params.api.getDisplayedRowAtIndex(params.rowIndex).data;

                    eGui.classList.add('custom-tooltip');
                    //@ts-ignore
                    eGui.style['background-color'] = color;
                    eGui.innerHTML = `
                            <p>
                                <span class"name">${data.task_name}</span>
                            </p>
                            <p>
                                <span>Country: </span>
                                ${data.percent_work}
                            </p>
                            <p>
                                <span>Total: </span>
                                ${data.task_finish_date}
                            </p>
                        `;
                }

                getGui() {
                    return this.eGui;
                }
                }""")
        return tooltip

```

I wanted to know how I can set the style of the popup I want, would anyone know how?

---

<div class="post-metadata">

**Author:** ![Pedro\_Henrique\_Rocha](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/pedro_henrique_rocha/32/34325_2.png) [@Pedro\_Henrique\_Rocha](https://discuss.streamlit.io/u/Pedro_Henrique_Rocha)\
**Post date:** [November 9, 2023, 6:06pm UTC](https://discuss.streamlit.io/t/using-the-tooltip-component/36616/4 "2023-11-09T18:06:07Z")

</div>

Hi Nauane! I’m facing a problem similar as what you faced. In my case, I want to display a tooltip in the column header, if you see this message I want to ask you if you can send your code, and then I could compare to mine.
