New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Enabling ForeignKey Column Sorting by Text
Environment
Product | Progress Telerik UI for ASP.NET MVC Grid |
Progress Telerik UI for ASP.NET MVC version | Created with the 2023.1.314 version |
Description
How can I enable ForeignKey
column sorting by text in the Telerik UI for ASP.NET MVC Grid?
Solution
The following example demonstrates how to enable the sort-by-text functionality in a ForeignKey column by adding the text field in the Grid.
To achieve the desired scenario:
- Add the complex model field that is corresponding for the ForeignKey column.
- Subscribe to the
document.ready()
event, get a reference of the header for the ForeignKey column, and change the data-field attribute to point to the text field.
Model.cs
public class ProductViewModel
{
public int ProductID
{
get;
set;
}
public string ProductName
{
get;
set;
}
public decimal UnitPrice
{
get;
set;
}
public CategoryViewModel Category
{
get;
set;
}
public int? CategoryID { get; set; }
}
For the complete implementation of the suggested approach, refer to the Telerik REPL example on enabling foreign key column sorting by text in the Grid.