Tips for showing various column information as tooltips in ag grid's pivot mode

var ColumnDefinitions = [{
    headerName: "Column A",
    field: 'colA',
    rowGroup: true
  },
  {
    headerName: "Column B",
    field: 'colB',
    pivot: true,
    enablePivot: true
  },
  {
    headerName: "Column C",
    field: 'colC',
    rowGroup: true
  },
  {
    field: 'colD',
    aggFunc: 'first',
    valueFormatter: currencyFormatter,
    tooltip: function(params) {
      return (params.valueFormatted);
    },
  },
  {
    field: 'customTooltip',
    tooltipField: 'comment'
  },
  {
    field: 'colF'
  }
];
function currencyFormatter(params) {
  return params.value;
}

The code snippet above is taken from a previous question. While it works, I am looking to customize the tooltip for the 'colD' field using a different 'comment' field. This customization is needed due to the use of group and pivot in the ag-Grid configuration. Any suggestions on how to achieve this for group and pivot ag-Grid setups would be highly appreciated.

Answer №1

It may be challenging to retrieve data in your unique grid scenario, as the rows and columns have been altered from the original model due to pivoting.

One solution could be to extract this information from the grid itself. If you need aggregated information to be displayed in a tooltip, the function for the tooltip might look something like this:

tooltip: params => {
  const country = params.node.key;
  const year = params.colDef.pivotKeys[0];
  const athletesWithNumbers = this.state.rowData
    .filter(d => d.year == year)
    .filter(d => d.country === country)
    .filter(d => d.gold > 0)
    .map(d => d.athlete + ': ' + d.gold);
  return athletesWithNumbers.join(', ');
}

For a practical example, you can refer to this plunker - although it may not be the exact solution you are looking for, it can provide insight into possible approaches.

Answer №2

simply utilize the tooltipValueGetter function

{
   field: 'message',
   headerName: 'Message',
   headerTooltip: 'Message',
   width: 110,
   filter: 'agSetColumnFilter',
   tooltipValueGetter: (params) =>  `${params.value} some text`
}

https://i.sstatic.net/ghAMr.png

or apply the same method for tooltipValueGetter https://i.sstatic.net/0Q2v3.png

UPDATE:

Understood, it's simple

There is a property in Ag-grid called tooltipField - where you can select any field from the grid

For instance, in the 'sport' column, the tooltip is showing the data from the previous column

Example: https://plnkr.co/edit/zNbMPT5HOB9yqI08

https://i.sstatic.net/iClJA.png

OR

You can customize the data for each field using tooltipValueGetter with the following syntax:

tooltipValueGetter: function(params) {  
  return `Country: ${params.data.country}, Athlete: ${params.data.athlete}, Sport: ${params.data.sport}`;
},

Example: https://plnkr.co/edit/zNbMPT5HOB9yqI08

Result: https://i.sstatic.net/Wa24F.png

UPDATE 2

Hello there! I followed your code snippet and it worked as desired

And it works as you want

Example: https://plnkr.co/edit/zNbMPT5HOB9yqI08 https://i.sstatic.net/xvCuJ.png

UPDATE 3

A bit of manipulation and I was able to retrieve the data

{ field: 'gold', aggFunc: 'sum',
    tooltipValueGetter: function(params) {  
    var model = params.api.getDisplayedRowAtIndex(params.rowIndex);
    return model.allLeafChildren[0].data.silver;
  },
},

The Last: https://plnkr.co/edit/9qtYjkngKJg6Ihwb?preview

Answer №3

    let ColDefinitions = [{
        headerName: "ColumnA",
        field: 'colA',
        rowGroup: true
      },
      {
        headerName: "ColumnB",
        field: 'colB',
        pivot: true,
        enablePivot: true
      },
      {
        headerName: "ColumnC",
        field: 'colC',
        rowGroup: true
      },
      {
        field: 'colD',
        aggFunc: 'last',
    tooltipValueGetter: customTooltipValueGetter
      },
      {
        field: 'comment'
      },
      {
        field: 'colF'
      }
    ];


    function customTooltipValueGetter(params) {
    const pivotKey = params.colDef.pivotKeys[0];
    let rowModel = params.api.getDisplayedRowAtIndex(params.rowIndex);
    for (let i = 0; i < rowModel.allLeafChildren.length ; i++) {
        if (rowModel.allLeafChildren[i].data.colB === pivotKey) {
          return rowModel.allLeafChildren[i].data.comments;
        }
      }
  }

This solution was derived from multiple sources to address the specific question at hand. For more details and context, please refer to the answers provided by @wctiger and @shuts.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The toLowerCase method seems to be malfunctioning along with several other functions

JS var score = 0 var yes = "yes" var pokemonName = []; var bg = []; var index = 0; document.getElementById('repete').style.visibility = 'hidden'; (function asyncLoop() { background = bg[num = Math.floor(Math.random() ...

Ways to specify an unused parameter within a function

As I work on my code, I encounter the need to separate the key and value from a request params object in order to validate the value using ObjectID. To achieve this, I decided to iterate over an array of entries and destructure the key and value for testin ...

When deployed, Angular 14 and Bootsrap 5 are functioning properly on a local environment but encountering issues on an online

My Angular application (version 14.2.0) is integrated with bootstrap (version 5.2.3). Upon building and deploying the application on a local IIS server, everything displays correctly as shown in the image below: https://i.sstatic.net/pLDs6.jpg However, w ...

Employing the powerful Math.pow() function within the setState() method

In this ReactJS code example, the goal is to update the value of a div element with every click of a button using the Math.pow() method. However, it seems that the method is not working as intended. Can someone explain why? The handlerButton function in ...

React js: Caution - Ensure each child within a list is assigned a distinct "key" property

One of the most frequently asked questions in React is regarding the key prop in the Todo component. Despite passing the id and using it as the key, some users still encounter errors. Various solutions have been attempted without success. Even though the ...

Is there a way to effortlessly launch a new window with just a single click?

I'm encountering an issue with a function that is supposed to open a new window when a button is clicked. Strangely, on the first click, nothing happens, but on the second click, the window finally opens. Here's my code: Script <script src ...

An error was encountered while linting /app/layout.tsx at line 16: Rule "@typescript-eslint/no-empty-function" was violated due to inability to read properties of undefined (reading 'getTokens')

I am puzzled as to why the function that generates JSX is being checked by the "next lint" script with the rule "@typescript-eslint/no-empty-function". The code snippet at line 16 of the layout.tsx file looks like this: export default function RootLayout( ...

Retrieving Array keys from PHP using jQuery

As a beginner in jQuery, I am eager to learn how to retrieve Array keys from a php file using jQuery. Currently, I have jQuery code set up to send input to file.php and execute a query on every keyup event. When file.php echoes the result, it looks somet ...

AngularJS's ng-repeat feature is not properly re-embedding tweets

In my project, I am utilizing angularjs to showcase tweets. The implementation involves using ng-repeat alongside a filter that is directly linked to the state of a checkbox. When the checkbox is checked, the filter returns all the tweets (the default beha ...

assigning attributes to web addresses

Is there a way to set a style property for webpages by targeting addresses that contain /index.php/projecten/ instead of specifying each complete address in the code? Currently, I am using the following code: <ul class="subnavlist" style="display: &l ...

Update or Delete BreezeJS EntityManager After Losing Instance Reference

In the process of developing a CRM application with a single-page application structure, I am integrating BreezeJS and AngularJS. The implementation involves utilizing dynamically-generated tabs to display various modules. Each time a user clicks on a menu ...

Configure Protractor's configuration file to utilize a personalized reporter

I'm in the process of setting up end-to-end tests using protractor.js, but I am not happy with how the default reporter displays results on my terminal window. Is there a way to customize the reporter configuration to make it easier to read and more ...

How can I click on an item when using pagination?

When using react.js, I am encountering a difficult-to-understand error. My component works fine without pagination - it displays all items and allows you to click on them. Pagination is working properly as well, but the issue arises when trying to click on ...

How can I modify the URL path using react-i18next?

I've been grappling with this problem for the past few days. My React app is causing me some trouble as I try to implement multilingual support using i18next. I aim to modify the URL path based on the selected language, such as http://localhost:3000/e ...

"Exploring the World Wide Web with JavaScript and Ajax in Internet

Is there a way to include a Javascript snippet at the end of some ajax content? It seems to be functioning properly in Firefox, but when I try it in Internet Explorer, the script is printed out without being executed. <script type="text/javascript"&g ...

Remove an element from an array within an object stored in a MongoDB document

Greetings and thank you for taking the time to read my query! I am currently diving into the world of coding, and here's my first question on this platform: I have a MongoDB collection structured similarly to the example below. Each document represe ...

React material-ui responsive carousel is a versatile tool that allows for

I am in the process of creating a music tour website using React material-ui. My goal is to replicate the design of this website: As a newcomer to React, I explored libraries like bootstrap and material-ui before settling on material-ui. However, I'm ...

Update the image within the svg tag

I am attempting to modify a preexisting SVG element within an HTML document. Here is the current code: <svg class="logo" viewBox="0 0 435 67"> <!-- IMAGE DIMENSIONS --> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#logo- ...

unable to locate the font file I recently downloaded in the Windows terminal

Interested in customizing your Windows terminal? I recently decided to change my font style and downloaded the desired one. However, despite seeing the font in control panel and trying the "downloading for every user" option, my terminal still can't l ...

In JavaScript, the "this" keyword points to a different object

Here is a script that needs attention: Bla = function() { this.prop = 123; } Bla.prototype.yay = function() { console.log(this,this.prop); } X = new Bla(); $(document).ready(X.yay); // output: #document undefined --> why? $(document).ready(functio ...