How can I force Kendo Grid to use a numeric filter on a column

爱⌒轻易说出口 提交于 2019-12-05 19:36:47

The solution is to specify that the value is an int in the model - change the DataSource method as so:

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

You can also use this solution:

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

I have faced similar issue when the filter are coming for data type string while my data type is "number", this happens if there is a discrepancy in declaring the schema, make sure the field declared in schema are correct i.e. have same name as the data you are getting/supplying to grid.

Kendo will be able to select a right filter type for each column, but you have to use properties instead of fields in TargetsModel.

For example, use this:

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

instead of this:

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

If for some reason you are unable to do this, the .Model() approach is probably the best way.

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