Hello,
I am building a Pivot table and I would like to pass some fields from the datasource feeding the Pivot table to:
While excluding those fields from showing in the Rows, Columns and Value fields of the Pivot table.
How would I achieve this (if it's even possible)?
For example, in your demo Pivot Table (https://ej2.syncfusion.com/aspnetcore/PivotTable/Default#/bootstrap5 ), let's say that :
- I want the "Country" not to show in the Pivot Table but in a tooltip for the value cell
- I want the "Country" value to be used in an Hyperlink
- I want the "Sale amount" not to show in the Pivot Table but be used in conditional formatting logic so the value cell for "Units sold" shows as green background if " Sale amount" > $1,000,000.
Thank you !
Hi Loic,
Please find the details below.
|
Query |
Comments |
|
|
I want the "Country" not to show in the Pivot Table but in a tooltip for the value cell |
Please create a custom tooltip in the pivot table's dataBound event to meet your requirements. You can add specific field information from the current cell's data to the tooltip content that will be displayed while hovering on each values in the pivot table. Please refer the below code example.
Code Example:
Screenshot: In_Stock field is not bind in report but shown in tooltip. |
|
|
I want the "Country" value to be used in an Hyperlink |
Using HyperlinkCellClick event, you can customize the specific cell’s hyperlink based on your needs. Please refer the code example below.
Code Example:
Please refer the below UG document to know more about HyperlinkCellClick event
Document: https://ej2.syncfusion.com/aspnetcore/documentation/pivot-table/hyper-link#event |
|
|
- I want the "Sale amount" not to show in the Pivot Table but be used in conditional formatting logic so the value cell for "Units sold" shows as green background if " Sale amount" > $1,000,000. |
Using conditional formatting, you can apply formatting to the specific field with that field data alone. However, you can use queryCellInfo event to apply the custom styles for the cells based on the field value which is not bind in the report. Please refer the code example below and screenshot.
Code Example:
Screenshot: Apply custom styles to the Sold and Amount field based on In_Stock values. However, we didn’t recommend this method because this leads to performance constraint. |
Meanwhile, we have prepared a sample for your reference below.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTable538456651
Please let us know if you have concerns.
Regards,
Angelin Faith Sheeba
Hi Angelin.
I was not able to use your sample.
When looking through the debugger, I see that the "indexObject" is null for me for all columns except the first one :
That IndexObject gives me the index of the objects from the datasource array for the whole row.
So, I cannot "map" a cell to its associated array from the datasource, which I would need to retrieve the appropriate data from the datasource.
Potentially I could loop through the indexObject of the first column for a particular row and identify those index from the datasource that match the current column but that seems inefficient.
How can I simply "map" a cell to the associated datasource objects ?
Note that I am using .NET 6 (your sample was on .NET Core 3.1).
Thank you.
Also, I forgot to add, I am using EJ2 AspNet Core version 20.2.0.48.
Hi Loic,
We believe the you missed enabling the drillthrough feature, which allows you to obtain the "indexObject" of each pivot value in the "queryCellInfo" event. Please see the code example below for more information.
Code example:
|
<ejs-pivotview id="pivotview" allowDrillThrough="true"> </ejs-pivotview> |
However, we don’t have any other easiest way to map a cell to the associated datasource objects. And the version is not a problem for this.
Please let us know if you have any concerns.
Regards,
Angelin Faith Sheeba.
Hi Angelin,
you are right !! Adding allowDrillThrough="true" now shows the "indexObject" for each cell correctly.
You're the best ! Thanks for all your help !
Hi Loic,
Please contact us if you have any other queries. We are always happy to assist you.
Regards,
Angelin Faith Sheeba.