【问题标题】:How can I force Kendo Grid to use a numeric filter on a column如何强制 Kendo Grid 在列上使用数字过滤器
【发布时间】:2014-08-25 19:14:27
【问题描述】:

使用以下代码,Kendo Grid 使用t.Files.Count 的字符串过滤器接口,即使类型是int。如何强制网格改为使用数字过滤器 UI?

@(Html.Kendo().Grid<GJW_Site.Web.Models.TargetsModel>()    
    .Name("grid")
    .Columns(columns => {
        columns.Bound(t => t.ID).Width(80);
        columns.Bound(t => t.OrbitalPeriod);
        columns.Bound(t => t.Files.Count);
    })
    .Sortable()
    .Filterable()
    .DataSource(dataSource => dataSource.Ajax()
        .PageSize(20)
        .Read(read => read.Action("Targets_Read", "Targets"))
    )
    .Resizable(o => o.Columns(true))
    .ColumnMenu()
)

为字符串生成一个过滤菜单:

我正在使用 Kendo.MVC 2013.1.514.340

【问题讨论】:

    标签: c# kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    解决方案是在模型中指定该值为int - 将DataSource 方法更改为:

    .DataSource(dataSource => dataSource.Ajax()
        .PageSize(20)
        .Read(read => read.Action("Targets_Read", "Targets"))
        .Model(m => {
            m.Field<int>(t => t.Files.Count);
        })
    )
    

    【讨论】:

    • 这正是我想要的
    【解决方案2】:

    您也可以使用此解决方案:

    .DataSource(dataSource => dataSource.Ajax()
        .PageSize(20)
        .Read(read => read.Action("Targets_Read", "Targets"))
        .Model(m => {
            m.Field("Files.Count", typeof(System.Int32));
        })
    )
    

    【讨论】:

      【解决方案3】:

      当我的数据类型为“数字”时,当过滤器用于数据类型字符串时,我遇到了类似的问题,如果声明架构存在差异,则会发生这种情况,请确保架构中声明的字段正确,即具有相同命名为您正在获取/提供给网格的数据。

      【讨论】:

        【解决方案4】:

        Kendo 将能够为每一列选择正确的过滤器类型,但您必须在 TargetsModel 中使用 properties 而不是 fields

        例如,使用这个:

        public class TargetsModel
        {
            public int ID { get; set; }
            public string OrbitalPeriod { get; set; }
            ...
        }
        

        而不是这个:

        public class TargetsModel
        {
            public int ID;
            public string OrbitalPeriod;
            ...
        }
        

        如果由于某种原因您无法做到这一点,.Model() 方法可能是最好的方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多