Hyperlink in Blazor Pivot Table Component
17 Dec 202211 minutes to read
The pivot table supports to show hyperlink option to link data for individual cells that are displayed in the component. Also, the hyperlink can be enabled separately for row headers, column headers, value cells, and summary cells using the PivotViewHyperlinkSettings class. It can be configured through the code behind, during initial rendering and the settings available to show the hyperlink are:
- ShowHyperlink: It allows to set the visibility of hyperlink in all cells.
- ShowRowHeaderHyperlink: It allows to set the visibility of hyperlink in row headers.
- ShowColumnHeaderHyperlink: It allows to set the visibility of hyperlink in column headers.
- ShowValueCellHyperlink: It allows to set the visibility of hyperlink in value cells.
- ShowSummaryCellHyperlink: It allows to set the visibility of hyperlink in summary cells.
- HeaderText: It allows to set the visibility of hyperlink based on header text.
- ConditionalSettings: It allows to set the visibility of hyperlink based on specific condition.
NOTE
By default, the hyperlink options are disabled for all cells in the pivot table.
NOTE
User defined style can be applied to hyperlink using CssClass property in PivotViewHyperlinkSettings class.
Hyperlink for all cells
The pivot table has an option to show hyperlink option for all cells that are currently in display. To do so, user need to set ShowHyperlink to true.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails" ShowFieldList="true">
<PivotViewDataSourceSettings DataSource="@data">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<ProductDetails> data { get; set; }
protected override void OnInitialized()
{
this.data = ProductDetails.GetProductData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Hyperlink for row headers
The pivot table has an option to show hyperlink option for row header cells alone that are currently in display. To do so, user need to set ShowRowHeaderHyperlink to true.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowRowHeaderHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<ProductDetails> data { get; set; }
protected override void OnInitialized()
{
this.data = ProductDetails.GetProductData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Hyperlink for column headers
The pivot table has an option to show hyperlink option for column header cells alone that are currently in display. To do so, the user need to set ShowColumnHeaderHyperlink to true.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowColumnHeaderHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<ProductDetails> data { get; set; }
protected override void OnInitialized()
{
this.data = ProductDetails.GetProductData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Hyperlink for value cells
The pivot table has an option to show hyperlink option for value cells alone that are currently in display. To do so, the user need to set ShowValueCellHyperlink to true.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data" ExpandAll="true">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowValueCellHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<PivotViewData.DefaultData> data { get; set; }
protected override void OnInitialized()
{
this.data = PivotViewData.GetDefaultData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Hyperlink for summary cells
The pivot table has an option to show hyperlink option for summary cells alone that are currently in display. To do so, the user need to set ShowSummaryCellHyperlink to true.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data" ExpandAll="true">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowSummaryCellHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<PivotViewData.DefaultData> data { get; set; }
protected override void OnInitialized()
{
this.data = PivotViewData.GetDefaultData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Condition based hyperlink
The pivot table has an option to show hyperlink in the cells based on specific conditions. It can be configured using the PivotViewConditionalSettings class through code behind, during initial rendering. The settings required are:
- Measure: Specifies the value field name, in-order to set the visibility of hyperlink for the same when condition is met.
- Conditions: Specifies the operator type such as Condition.Equals, Condition.GreaterThan, Condition.LessThan, etc.
- Value1: Specifies the start value.
- Value2: Specifies the end value.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data" ExpandAll="true">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Sold" Caption="Units Sold"></PivotViewValue>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings CssClass="e-custom-class">
<PivotViewConditionalSettings>
<PivotViewConditionalSetting Measure="Sold" Conditions=Condition.Between Value1="100" Value2="200"></PivotViewConditionalSetting>
</PivotViewConditionalSettings>
</PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<PivotViewData.DefaultData> data { get; set; }
protected override void OnInitialized()
{
this.data = PivotViewData.GetDefaultData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Header based hyperlink
The pivot table has an option to show hyperlink in the cells based on specific row or column header. It can be configured using the HeaderText option through code behind, during initial rendering.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails">
<PivotViewDataSourceSettings DataSource="@data">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
<PivotViewFormatSettings>
<PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
</PivotViewFormatSettings>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings HeaderText="FY 2015" CssClass="e-custom-class"></PivotViewHyperlinkSettings>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<PivotViewData.DefaultData> data { get; set; }
protected override void OnInitialized()
{
this.data = PivotViewData.GetDefaultData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
}
Event
The event HyperlinkCellClicked fires on every hyperlink cell click.
It has following parameters - Cancel and CurrentCell. The parameter CurrentCell is used to customize the host cell element by any means. Meanwhile, when the parameter Cancel is set to true, applied customization will not be updated to the host cell element.
@using Syncfusion.Blazor.PivotView
<SfPivotView TValue="ProductDetails" ShowFieldList="true">
<PivotViewDataSourceSettings DataSource="@data">
<PivotViewColumns>
<PivotViewColumn Name="Year"></PivotViewColumn>
<PivotViewColumn Name="Quarter"></PivotViewColumn>
</PivotViewColumns>
<PivotViewRows>
<PivotViewRow Name="Country"></PivotViewRow>
<PivotViewRow Name="Products"></PivotViewRow>
</PivotViewRows>
<PivotViewValues>
<PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue>
</PivotViewValues>
</PivotViewDataSourceSettings>
<PivotViewHyperlinkSettings ShowHyperlink="true" CssClass="e-custom-class">
</PivotViewHyperlinkSettings>
<PivotViewEvents TValue="ProductDetails" HyperlinkCellClicked="hyperlink"></PivotViewEvents>
</SfPivotView>
<style>
.e-custom-class,.e-custom-class:hover {
text-decoration: underline !important;
color: blue !important;
}
.e-custom-class:hover {
color: red !important;
}
</style>
@code{
public List<ProductDetails> data { get; set; }
protected override void OnInitialized()
{
this.data = ProductDetails.GetProductData().ToList();
//Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
}
public void hyperlink(HyperCellClickEventArgs args)
{
args.CurrentCell.SetAttribute("data-url", "https://syncfusion.com/");//here we have redirected to Syncfusion on hyperlinkcell click
}
}
NOTE
Refer to the Blazor Pivot Table feature tour page for its groundbreaking feature representations. You can also explore the Blazor Pivot Table example to know how to render and configure the pivot table.