|
<SfGrid DataSource="@Employees">
<GridColumns>
<GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="Employee ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<HeaderTemplate>
@{
var employee = (context as EmployeeData);
<SfTooltip Target="#txt">
<TooltipTemplates>
<Content>
FirstName
</Content>
</TooltipTemplates>
<span id="txt">FirstName</span>
</SfTooltip>
}
</HeaderTemplate>
<Template>
@{
var employee = (context as EmployeeData);
<SfTooltip Target="#txt">
<TooltipTemplates>
<Content>
@employee.FirstName
</Content>
</TooltipTemplates>
<span id="txt">@employee.FirstName</span>
</SfTooltip>
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(EmployeeData.HireDate) HeaderText="Hire Date" Format="d" TextAlign="TextAlign.Right" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
|
|
<GridColumn Field=@nameof(EmployeeData.FirstName) HeaderText="First Name" Width="130">
<HeaderTemplate>
@{
var employee = (context as EmployeeData);
<SfTooltip>
<TooltipTemplates>
<Content>
FirstName
</Content>
</TooltipTemplates>
<span>FirstName</span>
</SfTooltip>
}
</HeaderTemplate>
<Template>
@{
var employee = (context as EmployeeData);
<SfTooltip>
<TooltipTemplates @key="@employee.FirstName">
<Content>
@employee.FirstName
</Content>
</TooltipTemplates>
<span>@employee.FirstName</span>
</SfTooltip>
}
</Template>
</GridColumn>
|
Note that you can use the title html attribute as well:
<HeaderTemplate>
<span title="Time Elapsed">Elapsed</span>
</HeaderTemplate>
Hi CharlesG,
Thanks for the update
Yes, you can use the title HTML attribute within the HeaderTemplate to display
a tooltip for your column header.
Regards,
Prathap Senthil
Hello,
Can you please tell me how to add a tooltip for below GridColumn for a Grid with TValue="ExpandoObject".
Hi Sandip Mane,
To add tooltips to columns in a Blazor DataGrid when using TValue="ExpandoObject", you can utilize the column template feature in combination with the SfTooltip component. Since you're working with ExpandoObject, the column values need to be accessed dynamically using dictionary-style access.
Code Snippet:
|
<GridColumn Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120" /> <GridColumn Field="CustomerID" HeaderText="Customer ID" Width="120"> <Template> @{ var data = context as IDictionary<string, object>; var value = data["CustomerID"]?.ToString(); <SfTooltip Position="Position.BottomLeft"> <ContentTemplate> @value </ContentTemplate> <ChildContent> <span>@value</span> </ChildContent> </SfTooltip> } </Template> </GridColumn> |
We have attached the concern sample please check and get back to us if you have any questions.
Regards,
Sanjay Kumar Suresh
Thanks
Hi Sandip Mane,
We are happy to hear that the provided solution was helpful. Please get back to us if you need any other assistance.
Regards,
Sanjay Kumar Suresh