Setting the default filter operator?

4 Answers 3424 Views
Grid
Nocklas
Top achievements
Rank 1
Nocklas asked on 10 Jul 2012, 02:16 PM
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"
        }
    }
}


4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 12 Jul 2012, 02:44 PM
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!
Ross
Top achievements
Rank 1
commented on 03 Oct 2012, 03:42 PM

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.
Alex
Top achievements
Rank 1
commented on 24 Jun 2013, 06:38 PM

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
0
Alexander Valchev
Telerik team
answered on 26 Jun 2013, 01:23 PM
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!
Alex
Top achievements
Rank 1
commented on 26 Jun 2013, 03:39 PM

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
Alexander Valchev
Telerik team
commented on 26 Jun 2013, 04:20 PM

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!
Ian
Top achievements
Rank 2
commented on 06 Dec 2013, 07:41 PM

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"))))
Alexander Valchev
Telerik team
commented on 09 Dec 2013, 02:31 PM

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!
Oscar
Top achievements
Rank 1
commented on 10 Dec 2013, 09:19 AM

Hi Alexander,
Your jsbin example doesn't work in IE10. When you click to expand the combo, it collapses immediatly.
Kind Regards
Oscar.
Alexander Valchev
Telerik team
commented on 10 Dec 2013, 11:34 AM

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!
Oscar
Top achievements
Rank 1
commented on 10 Dec 2013, 11:37 AM

That's right.
Thank you very much, Alexander.
Igor
Top achievements
Rank 1
commented on 09 Aug 2014, 03:14 PM

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
Alexander Valchev
Telerik team
commented on 11 Aug 2014, 01:39 PM

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!
 
Igor
Top achievements
Rank 1
commented on 11 Aug 2014, 01:49 PM

Works great

Thank you Alexander!
Mike
Top achievements
Rank 1
commented on 19 Dec 2014, 09:22 PM

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.
Lac
Top achievements
Rank 1
commented on 23 Feb 2015, 06:57 PM

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
Yadwinder
Top achievements
Rank 1
commented on 14 Mar 2015, 10:34 AM

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

Lac
Top achievements
Rank 1
commented on 16 Mar 2015, 04:07 PM

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")))                              
                       
;
Aaron
Top achievements
Rank 1
Veteran
commented on 22 Sep 2020, 10:08 PM

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?

Georgi
Telerik team
commented on 25 Sep 2020, 12:20 PM

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

Aaron
Top achievements
Rank 1
Veteran
commented on 25 Sep 2020, 01:13 PM

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

Tsvetomir
Telerik team
commented on 30 Sep 2020, 09:36 AM

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/.

0
Srinivasulu
Top achievements
Rank 1
answered on 16 Apr 2021, 09:28 PM
Just wanted to have string operators based on requirement  with extra filters , please let me know the snippet and also share the link for documentation
0
Tsvetomir
Telerik team
answered on 20 Apr 2021, 10:15 AM

Hi Srinivasulu,

Based on the provided information, I am not completely sure what the end solution should look like. Also, I am uncertain what would the requirement and when the condition should be executed. 

Is it possible for you to take a few moments and share more information on the exact scenario you are willing to achieve? Sharing a short video and/or screenshots would be of great help. 

Looking forward to your reply.

 

Regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Nocklas
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Srinivasulu
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or