Kendo Grid MVC: default filter for string fields is set to “is equal to”

烂漫一生 提交于 2019-12-24 09:37:27

问题


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())

回答1:


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())

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.




回答2:


If you have source code open kendo solution and find class name StringOperators under Kendo.Mvc/UI/Grid/Settings

In Operators = new Dictionary<string, string>() change the order as you wish , reBuild the solution and then overwrite generated file in your project.



来源:https://stackoverflow.com/questions/17487534/kendo-grid-mvc-default-filter-for-string-fields-is-set-to-is-equal-to

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