Kendo Grid MVC:字符串字段的默认过滤器设置为“等于". [英] Kendo Grid MVC: default filter for string fields is set to "is equal to"

查看:67
本文介绍了Kendo Grid MVC:字符串字段的默认过滤器设置为“等于".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kendo Grid具有日历的"dt"字段等于"的默认过滤器.对于名称"字段,它具有默认的过滤器等于",但是我想将包含"移动到选项列表的第一位,并将其默认为字符串.如何实施?

Kendo Grid has default filter for "dt" field "is equal to" with calendar. For "name" field it has default filter "is equal to", but I want to move "Contains" to a first place of an option list and make it default for strings. How could it be implemented?

public class MyClass
{
    public DateTime dt { get; set; }
    public string name { get; set; }
}


@(Html.Kendo()
      .Grid<MyClass>()
      .Name("grid")
      .DataSource(data =>
                  data.Ajax()
                      .ServerOperation(false)
                      .Read(read =>
                            read.Action("MyAction", "MyController"))
      )
      .Columns(cols =>
          {
              cols.Bound(x => x.dt).Title("Date").Width(150);
              cols.Bound(x => x.name).Title("Name").Width(250);
          })
      .Filterable()
      .Sortable())

推荐答案

看看过滤器菜单自定义演示.看来您会按照以下方式进行操作:

Take a look at the Filter menu customization demo. It appears you would do something along these lines:

@(Html.Kendo()
      .Grid<MyClass>()
      .Name("grid")
      .DataSource(data =>
                  data.Ajax()
                      .ServerOperation(false)
                      .Read(read =>
                            read.Action("MyAction", "MyController"))
      )
      .Columns(cols =>
          {
              cols.Bound(x => x.dt).Title("Date").Width(150);
              cols.Bound(x => x.name).Title("Name").Width(250);
          })
        .Filterable(filterable => filterable
            .Extra(false)
            .Operators(ops => ops
                .ForString(str => str.Clear()
                    .Contains("Contains")
                    .StartsWith("Starts with")
                    // any other filters you want in there
                    )))
      .Sortable())

如果我正确地解释了它,那么 str.Clear()会清除存在的过滤器,以便您从那里构建自己的过滤器.因此,例如,如果您不认为客户需要或想要 .EndsWith 过滤器,则不要在此处包括它.

If I'm interpreting it correctly, the str.Clear() clears out the filters that exist so you'll be building your own from there. So if you don't think the client needs or wants the .EndsWith filter, for example, you would not include it here.

这篇关于Kendo Grid MVC:字符串字段的默认过滤器设置为“等于".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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