Adding Dynamic Tooltip to Grid Header

Hi Team,

How to add the Dynamic tooltip content for the Grid Header ?

For Example, If you do sort a column the Header Tooltip should shows as Ascending, then if you sort it again then it should shows as Descending .

I have tried this, but it sets initially when the grid loads after that Tooltip content is not changing when I do sorting

headerCellInfo(args) {
     if (args.cell.column.field === 'Order') {
         const toolcontent = this.sortOptions.columns[0].direction;
         const tooltipTooltip = new Tooltip({
             content: toolcontent
         });
         tooltip.appendTo(args.node);
     }
    }


Thanks

Nambi R


3 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team August 4, 2021 06:54 AM UTC

Hi Nambi, 
 
Greetings from Syncfusion support. 
 
You can achieve your requirement of showing the sort order on the column header by assigning the tooltip content dynamically in its beforeOpen event as demonstrated in the below code snippet, 
 
public tooltip: Tooltip; 
 
// Grid’s headerCellInfo event handler 
headerCellInfo(args) { 
    if (args.cell.column.field === 'CustomerName') { 
        this.tooltip = new Tooltip({ 
            beforeOpen: this.beforeOpen.bind(this) 
        }); 
        this.tooltip.appendTo(args.node); 
    } 
} 
 
// Tooltip’s beforeRender event handler 
beforeOpen() { 
    if (this.grid.sortSettings.columns.length !== 0) { 
        // Condition is executed if there are sorted columns 
        this.grid.sortSettings.columns.forEach(col => { 
            if (col.field === 'CustomerName') 
                // The column’s sort direction is set as the tooltip content 
                this.tooltip.content = col.direction; 
        }) 
    } else { 
        // If the particular column is not sorted then the default content can be set here 
        this.tooltip.content = 'default'; 
    } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Marked as answer

NR Nambi Ramamoorthy August 4, 2021 12:52 PM UTC

Hi Sujith,


 Thanks. That works for me . 

 One thing I need to know is How to make the text (i.e., Ascending or Descending) to center in Tooltip ? 

 In below screenshot the text Descending is aligned to Left, I need it to be center.




Thanks,

Nambi



SK Sujith Kumar Rajkumar Syncfusion Team August 5, 2021 06:42 AM UTC

Hi Nambi, 
 
You’re welcome. 
 
And as for this query – “One thing I need to know is How to make the text (i.e., Ascending or Descending) to center in Tooltip ?”, you can achieve this requirement by setting the EJ2 tooltip component’s position property as TopCenter as demonstrated in the below code snippet, 
 
this.tooltip = new Tooltip({ 
    position: 'TopCenter',  
    beforeOpen: this.beforeOpen.bind(this) 
}); 
this.tooltip.appendTo(args.node);  
 
Please find the below modified sample for your reference, 
 
 
More details on the available tooltip positions can be checked in the below documentation link, 
 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon