外键列排序 [英] Foreign key column sorting

查看:61
本文介绍了外键列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Kendo网格与ForeignKey列一起使用进行排序.默认情况下,此列按值排序,但我们需要按文本排序.任何人都可以提供使用ASP.NET Wrappers进行操作的示例吗?

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?

推荐答案

我发现诀窍是在外键对象上实现IComparable,然后按文本名称而不是Kendo网格中的id进行排序:

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);
    }
}

用户和Telerik提到的所有其他解决方案看起来要复杂得多!

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

这篇关于外键列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆