Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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())
like image 607
user1820034 Avatar asked Sep 12 '25 20:09

user1820034


2 Answers

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.

like image 149
Elsimer Avatar answered Sep 17 '25 02:09

Elsimer


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.

like image 45
ehsan Avatar answered Sep 17 '25 03:09

ehsan