Grid column filter default method

13 posts, 1 answers
  1. Answer
    Fernando
    Fernando avatar
    56 posts
    Member since:
    Sep 2012

    Posted 26 Apr 2013 Link to this post

    Hello guys!

    On a grid, is it possible to change the default filter method for a string type column? To me, "contains" makes more sense than "is equal", as it will be used more often.

    We've tried to change it on the columnMenuInit event, but on the first attempt to filter, the DropDownList is reset to the "is equal" option.

    Thanks!
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 30 Apr 2013 Link to this post

    Hello Fernando,

    You can change the order in which the filter operators are defined for string type. This will affect the default/first filter option in the menu. Here is an example for this: http://jsbin.com/ulerib/2/edit

    Regards,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Fernando
    Fernando avatar
    56 posts
    Member since:
    Sep 2012

    Posted 30 Apr 2013 Link to this post

    Wow, we didn't realize the order on that option mattered. Thank you!
  5. Jonam
    Jonam avatar
    19 posts
    Member since:
    Aug 2010

    Posted 05 Jul 2013 Link to this post

    Great solution. Can somebody please provide the code example to this in asp.net MVC?
  6. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 09 Jul 2013 Link to this post

    Hi Fernando,

    Please check the example below:

    .Filterable(f =>
        f.Operators(o =>
            o.ForDate(d => d
                .Clear()
                .IsLessThanOrEqualTo("Less Than Or Equal To")
                .IsGreaterThanOrEqualTo("Greater Than Or Equal To")
                .IsLessThan("Less Than")
                .IsGreaterThan("Greater Than")
                .IsNotEqualTo("Not Equal To")
                .IsEqualTo("Equal To")
            )
        )
    )
    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Shawn
    Shawn avatar
    49 posts
    Member since:
    Jul 2011

    Posted 13 Jul 2013 Link to this post

    Is it possible to apply this at a global level? Instead of per grid?
  8. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 16 Jul 2013 Link to this post

    Hi Shawn,

     
    Basically this feature is not supported out-of-the-box and it will require custom solution. For example you can modify the Grid prototype options object - that way the grid will be initialized with different default options.

    e.g.:

    //you can execute that just after kendo.all/web script
    kendo.ui.Grid.prototype.options.filterable = true;

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  9. Jean-Baptiste
    Jean-Baptiste avatar
    1 posts
    Member since:
    Jul 2013

    Posted 19 Jul 2013 Link to this post

    Hello guys,

    I have updated the jsbin provided by Nikolay by adding a default filter on the datasource :
    filter: {field:"foo", operator:"eq", value:"foo"}
    http://jsbin.com/ulerib/13/edit

    It works as the filter is applied by default however the filter icon is not activated on the column..

    Any idea of a workaround ?

    Thanks!
  10. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 22 Jul 2013 Link to this post

    Hello Jean-Baptiste,

    This will work if you upgrade to latest version of Kendo UI.
    http://jsbin.com/ulerib/15/edit

    Regards,
    Nikolay Rusev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  11. DominionZA
    DominionZA avatar
    49 posts
    Member since:
    Jul 2007

    Posted 07 Apr 2015 in reply to Vladimir Iliev Link to this post

    Your MVC sample does not work for me.
    If I exclude "IsEqualTo" then the grid filter options render in the order I specify. As soon as I put IsEqualTo back in again, it defaults and ignores whatever I specified.

    This works as expected.
    .Filterable(f => f.Messages(m => m.IsFalse("No")).Messages(m => m.IsTrue("Yes"))
                    .Operators(
                        o => o
                            .ForString(s =>
                                s.Clear()
                                    .Contains("Contains")
                                    .DoesNotContain("Does not contain")
                                    //.IsEqualTo("Is equal to")
                                    .IsNotEqualTo("Is not equal to")
                                    .StartsWith("Starts with")
                                    .EndsWith("Ends with")
                            )
                    ))

    This defaults back to KendoUI defaults and ignores my code.
    .Filterable(f => f.Messages(m => m.IsFalse("No")).Messages(m => m.IsTrue("Yes"))
                    .Operators(
                        o => o
                            .ForString(s =>
                                s.Clear()
                                    .Contains("Contains")
                                    .DoesNotContain("Does not contain")
                                    .IsEqualTo("Is equal to")
                                    .IsNotEqualTo("Is not equal to")
                                    .StartsWith("Starts with")
                                    .EndsWith("Ends with")
                            )
                    ))
  12. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 09 Apr 2015 Link to this post

    Hello Michael,

    The reason for current behavior is that the Grid internally exports filter settings only if the collection of filters have different count than the default filters collection or at least one filter have different text. That why in current case I would suggest to simply add one empty space to the end of one of the messages as follows:

    .Filterable(f => f.Messages(m => m.IsFalse("No")).Messages(m => m.IsTrue("Yes"))
        .Operators(
            o => o
                .ForString(s =>
                    s.Clear()
                    .Contains("Contains")
                    .DoesNotContain("Does not contain")
                    .IsEqualTo("Is equal to")
                    .IsNotEqualTo("Is not equal to")
                    .StartsWith("Starts with")
                    .EndsWith("Ends with ")
                )
        ))

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  13. Jean-Philippe
    Jean-Philippe avatar
    5 posts
    Member since:
    Dec 2010

    Posted 07 Jul 2015 Link to this post

    This forces us to set the message for each operator. But we are using kendo.messages.fr-FR.js

    So now we have to set the proper french message for each operator in each grid... this is a major maintenance issue.

    Is there any way doing this without override messages?

    Thanks

  14. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 09 Jul 2015 Link to this post

    Hello Jean,

    Currently there is no other way other than overriding the messages as demonstrated in the following example:

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready