Setting the default filter operator?

23 posts, 0 answers
  1. Nocklas
    Nocklas avatar
    7 posts
    Member since:
    Jun 2012

    Posted 10 Jul 2012 Link to this post

    How do I set the default filter operator in a grid?

    I define my operators in the following way, and the default operator is Is Equal To. I would like to have Contains as my default operator.

    filterable: {
        extra: false//do not show extra filters
        operators: { // redefine the string operators
            string: {   
                contains: "Contains",
                startswith: "Starts With",
                eq: "Is Equal To"
            }
        }
    }


  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 12 Jul 2012 Link to this post

    Hello Niclas,

    I am afraid this is not supported out of the box, by default the selected operator is "eq". As a workaround you could manually select the drop down item after the filter menus are rendered. For example:
    dataBound: function(e) {
        //get the dropdowns
        var dropDowns = $(".k-filter-menu").find("[data-role=dropdownlist]");
        //select the first element as defined in the filterable configuration
        setTimeout(function() {
            dropDowns.eq(0).data("kendoDropDownList").select(0); //select the first option
            dropDowns.eq(0).data("kendoDropDownList").trigger("change"); //trigger the change
        });
    }

    Unfortunately if you decide to use this approach, you will have to hard code the drop down index. As a general information, the select list options will be ordered in the same way as they are defined in the filterable configuration.
    I hope this helps.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Ross
    Ross avatar
    11 posts
    Member since:
    Aug 2012

    Posted 03 Oct 2012 Link to this post

    Is this fixed yet in version 2012.2.913?  I need all columns in my grid filter to default to "contains".  Are there any other better work arounds because this example above does not seem to change it to contains for all columns in my gird.
  4. Alex
    Alex avatar
    26 posts
    Member since:
    Jun 2011

    Posted 24 Jun 2013 Link to this post

    Hi Kendo,

    I need the same things as Ross did. "  I need all columns in my grid filter to default to "contains""
    Is this feature available yet?
    If not, is there any work around solutions?

    Thank you,

    Alex Nguyen
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 26 Jun 2013 Link to this post

    Hello guys,

    I am glad to inform you that the issue is fixed in the latter release. Please download Kendo UI v2013.1.514 or newer and give it a try.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Alex
    Alex avatar
    26 posts
    Member since:
    Jun 2011

    Posted 26 Jun 2013 Link to this post

    Hi Alexander,

    Thank you for the quick reply.  Is there any document/instruction how to achieve it? Is there any sample code available?

    Thank you,
    Alex
  7. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 26 Jun 2013 Link to this post

    Hi Alex,

    Corresponding documentation could be found at the following link:
    For your convenience I prepared a small example: http://jsbin.com/ebosig/2/edit

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Ian
    Ian avatar
    73 posts
    Member since:
    Jun 2013

    Posted 06 Dec 2013 Link to this post

    I've tried this in MVC 4, but it's not limited the operators to just Contains:

                  columns.Bound(c => c.Title)
                      .Filterable(filter=>filter
                          .Extra(false)
                          .Operators(o=>o.ForString(f=>f.Contains("Contains"))))
  9. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 09 Dec 2013 Link to this post

    Hello Ian,

    In MVC wrappers you should call the .Clear() method at first.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  10. Oscar
    Oscar avatar
    185 posts
    Member since:
    Oct 2010

    Posted 10 Dec 2013 Link to this post

    Hi Alexander,
    Your jsbin example doesn't work in IE10. When you click to expand the combo, it collapses immediatly.
    Kind Regards
    Oscar.
  11. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 10 Dec 2013 Link to this post

    Hi Oscar,

    I believe that the issue is caused by the jsBin itself. The issue does not occur when you view the same sample in a full screen result screen:

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  12. Oscar
    Oscar avatar
    185 posts
    Member since:
    Oct 2010

    Posted 10 Dec 2013 Link to this post

    That's right.
    Thank you very much, Alexander.
  13. Igor
    Igor avatar
    8 posts
    Member since:
    Aug 2012

    Posted 09 Aug 2014 Link to this post

    Hello,

    I tried the same thing with the new filter row option, but it does not work. Here is an example: http://jsbin.com/sopeteju/1/

    Is there a workaround for this problem?

    Best,
    Igor
  14. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 11 Aug 2014 Link to this post

    Hello Igor,

    In case you are using the new filter row feature you should specify the default cell operator explicitly.

     

    Please check the updated code sample: http://jsbin.com/xusim/1/edit

    Regards,
    Alexander Valchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  15. Igor
    Igor avatar
    8 posts
    Member since:
    Aug 2012

    Posted 11 Aug 2014 in reply to Alexander Valchev Link to this post

    Works great

    Thank you Alexander!
  16. Mike
    Mike avatar
    23 posts
    Member since:
    Jul 2008

    Posted 19 Dec 2014 in reply to Alexander Valchev Link to this post

    I want "Contains" to be the default operator but I like all the other filtering options so I tried just reordering them:

    .Filterable(filterable => filterable
        .Extra(false)
        .Operators(operators => operators
            .ForString(str => str
                .Clear()
                .Contains("Contains")
                .DoesNotContain("Does not contain")
                .StartsWith("Starts with")
                .EndsWith("Ends with")
                .IsEqualTo("Is equal to")
                .IsNotEqualTo("Is not equal to")
            )
        )
    )

    Unfortunately the filter list is displayed the the default order, not the order I specified. If I change anything about one of the filters (e.g., add a trailing space) then I get the order I specified.
  17. Lac
    Lac avatar
    2 posts
    Member since:
    Oct 2014

    Posted 23 Feb 2015 in reply to Mike Link to this post

    I had the same problem and could not figure out why. At first, I thought it's because I used an older version of Kendo UI so I upgraded to MVC 5 version and still got the same problem. After two days, I figured out the problem was because of older versions of kendo javascript and css.  Following this example and updating the css and js files accordingly, I have it working now. Hope it helps someone else.

    http://jsbin.com/zeqocamora/1/edit
  18. Yadwinder
    Yadwinder avatar
    1 posts
    Member since:
    Feb 2015

    Posted 14 Mar 2015 Link to this post

    Hello 

    I'm doing something like below to set contains as default filter:

    .Filterable(filterable => filterable
                                    .Extra(false)
                                    .Operators(operators => operators
                                        .ForString(str => str.Clear()
                                            .Contains(Strings.FilterContains)
                                            .StartsWith(Strings.FilterStartswith)
                                            .IsEqualTo(Strings.FilterIsEqualTo)
                                            .IsNotEqualTo(Strings.FilterIsNotEqualTo)
                                        ))
                                   )

    But it doesn't work in IE. please help asap.

    Thanks,
    Yadwinder

  19. Lac
    Lac avatar
    2 posts
    Member since:
    Oct 2014

    Posted 16 Mar 2015 in reply to Yadwinder Link to this post

    You know what I found eventually? Updating Telerik javascript and stylesheet will fix it.  I’m not sure which file actually fixed the
    problem because I updated several of them at the same time but I suspect it’s the stylesheet files because if I remember correctly, after updating all javascript files, I still had the problem. So I recommend that you update the stylesheet files first to see if it fixes your issue.  Anyway, here’re the files that I updated.

    Kendo.all.min.js
    Kendo.aspnetmvc.min.js- v2012.2.710
    Kendo.dataviz.min.css- v2013.1.514
    Kendo.default.mn.css - v2013.1.514
    Kendo.common.min.css- v2013.1.514


    Then I have my code
    like this:

    .Filterable(f => f
                                    .Extra(true)
                                    .Operators(o=> o                                   
        .ForString(s => s                                       
    .Clear()                                       
    .Contains("Contains")
    .IsEqualTo("Is equal to")
    .IsNotEqualTo("Is not equal to")
    .StartsWith("Starts with")
    .EndsWith("Ends with")
     ))
     .Cell(cell
    => cell.Operator("Contains")))                              
                           
    ;
  20. Aaron
    Aaron avatar
    13 posts
    Member since:
    Aug 2020

    Posted 22 Sep 2020 Link to this post

    I tried this on a Grid and found it worked successfully to list the operators in the order specified, with the first (contains) being the default:

    .Filterable(filter => filter
       .Operators(op => op
          .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")
             .IsNullOrEmpty("Is empty")
             .IsNotNullOrEmpty("Is not empty"))
          ))

     

    I tried what appears to be the equivalent for the Filter control:

    .Operators(o =>
    {
       o.String(s =>
       {
          //s.Clear();
          s.Contains("Contains");
          s.Doesnotcontain("Does not contain");
          s.Eq("Is equal to");
          s.Neq("Is not equal to");
          s.Startswith("Starts with");
          s.Endswith("Ends with");
          s.Isnullorempty("Is empty");
          s.Isnotnullorempty("Is not empty");
       });
    })

     

    While there aren't any errors, and I can customize the text that is displayed for the Filter component's operators, it doesn't appear that this can be used to control the order in which the operators are displayed on-screen (and the first one listed doesn't become the new default operator). Can anyone confirm that this is in fact how this is supposed to work, and this nearly identical feature works differently when used in a Grid control compared to the Filter control? Or am I by chance just missing something that is causing the inconsistent behavior?

  21. Georgi
    Admin
    Georgi avatar
    703 posts

    Posted 25 Sep 2020 Link to this post

    Hello Aaron,

    Indeed the behavior is not expected and the order should be preserved. We have it logged to our backlog and we will do our best to fix it as soon as possible.

    You can track the status of the issue in the link below:

    We apologize for the inconvenience this might have caused you and thank you for your understanding.

    Regards,
    Georgi
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

  22. Aaron
    Aaron avatar
    13 posts
    Member since:
    Aug 2020

    Posted 25 Sep 2020 in reply to Georgi Link to this post

    Thanks for the update, and for creating the issue on GitHub!

    Any idea as to when (or if) this might be resolved? I'm not looking for a hard date to hold you to or anything, I'm just curious if it's fairly safe to assume that this will be addressed within the next 6-12 months (or if this is merely an acknowledgement of the issue but it could go unresolved for years).

  23. Tsvetomir
    Admin
    Tsvetomir avatar
    837 posts

    Posted 30 Sep 2020 Link to this post

    Hi Aaron,

    My name is Tsvetomir and I would like to inform you that the issue is undergoing active development. I cannot provide an exact date for its release, however, expect it to be in any of the upcoming releases. 

     

    Kind regards,
    Tsvetomir
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top