How to pass and retrieve custom data in Pivot Table?


AB

Account 1 [linkto="account1_link"]

1010
Account 2  [linkto="account2_link"]
1415


dataSource = [
  {account: 'Account 1', name: 'A', value: '10', link: 'account1_link'},
  {account: 'Account 1', name: 'B', value: '10', link: 'account1_link'},
  {account: 'Account 2', name: 'A', value: '14', link: 'account2_link'},
  {account: 'Account 2', name: 'B', value: '15', link: 'account2_link'}
];

I have simple Pivot Table like the above. I would like to make my row headers a hyperlink. What can I do to get "account1_link" in my row header?


Thanks


5 Replies 1 reply marked as answer

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 31, 2022 09:17 AM UTC

Hi Simon,


You can use the enginePopulated event to apply hyperlink to a specific field. Then, based on your requirements. And you can bind the Url link to a certain field using the hyperlinkCellClick event. Please see the code example below.


Code Example:

var pivotObj = new ej.pivotview.PivotView({

enginePopulated: function (args) {

    for (var i = 0i < args.pivotValues.lengthi++) {

      for (

        var j = 0;

        args.pivotValues[i] != null && j < args.pivotValues[i].length;

        j++

      ) {

        if (

          args.pivotValues[i][j] != null &&

          args.pivotValues[i][j].axis == 'row' &&

          args.pivotValues[i][j].actualText !== 'Grand Total'

        ) {

          args.pivotValues[i][0].enableHyperlink = true// here you can enable the hyperlink to specific field cells

        }

      }

    }

  },

 

  hyperlinkCellClick: (args=> {

    if (args.currentCell.querySelector('a') && args.data.actualText!=="Grand Total") {

      args.currentCell

        .querySelector('a')

        .setAttribute(

          'data-url',

          pivotObj.dataSourceSettings.dataSource[args.data.index[0]]['link']

        );

      args.cancel = false;

    }

  }

});


Meanwhile, we have prepared a sample for your reference.


Sample: https://stackblitz.com/edit/kq1aff-4ifx6w?file=index.js


Please see the below UG document for more information on the “hyperlinkCellClick " event.


Document: https://ej2.syncfusion.com/javascript/documentation/pivotview/hyper-link/#event


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Marked as answer

SS Simon Soong June 1, 2022 09:31 AM UTC

Hi, thanks for your reply. However this is not my case. The 'link' can be different for each row rather than hard coded as a string 'link'.


I'm thinking the 'link' for each row would be retrieved from API as dataSource.


Any solution to that?



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team June 2, 2022 02:05 PM UTC

Hi Simon,


In the given data source, we have a “link” property that contains unique anchor links for each row displayed in the pivot table.  Please see the screenshot below for more information. While performing hyperlink cell click, the links were connected to the corresponding row headers using the hyperlinkCellClick event. As a result, whenever you click the row headers, your browser will open a specific link. For your convenience, we've included a video link.


Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/hyperlink368516127


Screenshot:

Text

Description automatically generated


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.



SS Simon Soong June 3, 2022 07:36 AM UTC

Greetings,


Thanks for the solution. This is exactly what I want to achieve.


Regards,

Simon Soong



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team June 6, 2022 07:18 AM UTC

Hi Simon,


Please let us know if you have any other queries. We are always happy to assist you.


Regards,

Angelin Faith Sheeba.


Loader.
Up arrow icon