New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Exporting Links To Excel
Environment
Product | Grid for Progress® Telerik® UI for ASP.NET Core |
Description
I have a Telerik UI for ASP.NET Core Grid column that contains a hyperlink. The link is clickable in the Grid. However, when I export the data to Excel, I can no longer interact with it. I want to be able to click on the exported links.
Solution
The Workbook API
exposes a configuration that enables you to set hyperlinks to specific cells.
To achieve the desired outcome:
- Configure a column with by using the Template component.
- Subscribe to the
ExcelExport
event of the Grid. - Within the handler, generate the
hyperlinks
array by using information from the already generated Workbook. - (Optional) Define an optional method that enables you to convert the current Grid column index to a corresponding Excel column name. For example:
A, B, C ... AA
.
Razor
@{
var data = new List<GridModel>()
{
new GridModel
{
Name = "Jane Doe",
Link = "https://google.com"
},
new GridModel
{
Name = "Jane Doe",
Link = "https://youtube.com"
}
};
}
@(Html.Kendo().Grid<GridModel>()
.Name("grid")
.ToolBar(toolbar => toolbar
.Excel()
)
.Columns(columns =>
{
columns.Bound(column => column.Name);
columns.Bound(column => column.Link).ClientTemplate(Html.Kendo().Template()
.AddHtml(@<text>
<a href="${data.Link}">${data.Link}</a>
</text>)
);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Read_Data", "Grid"))
)
.Events(events => events.ExcelExport("onExcelExport"))
.BindTo(data)
)