Foreign key column sorting

送分小仙女□ 提交于 2019-12-10 19:56:13

问题


I'm using Kendo grid with ForeignKey column with sorting. By default this column is sorted by value but we need it to be sorted by text. Could anyone provide please an example of doing it using ASP.NET Wrappers?


回答1:


I found the trick was to implement IComparable on the foreign key object, which then sorts by the text name instead of the id in the Kendo grid:

public class MyForeignKeyModel : IComparable<MyForeignKeyModel>
{
    public int ID { get; set;}

    public string Name { get; set;}

    public int CompareTo(MyForeignKeyModel compareTo)
    {
        return String.Compare(Name, compareTo.Name, StringComparison.InvariantCulture);
    }
}

All the other solutions mentioned by users and Telerik look much more complicated!




回答2:


Reponse by Atanas Korchev (Admin, Kendo UI) We can’t support this in all cases because the data source won’t have all data (it usually has just the foreign key which is the value)

You can use Grouping if that helps to some extend.



来源:https://stackoverflow.com/questions/16456439/foreign-key-column-sorting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!