This is a migrated thread and some comments may be shown as answers.

Grid column filter default method

12 Answers 1733 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fernando
Top achievements
Rank 1
Fernando asked on 26 Apr 2013, 09:19 PM
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!

12 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 30 Apr 2013, 07:58 AM
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!
0
Fernando
Top achievements
Rank 1
answered on 30 Apr 2013, 11:46 AM
Wow, we didn't realize the order on that option mattered. Thank you!
0
Jonam
Top achievements
Rank 1
answered on 05 Jul 2013, 07:14 AM
Great solution. Can somebody please provide the code example to this in asp.net MVC?
0
Vladimir Iliev
Telerik team
answered on 09 Jul 2013, 08:16 AM
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!
0
Shawn
Top achievements
Rank 2
answered on 13 Jul 2013, 07:26 AM
Is it possible to apply this at a global level? Instead of per grid?
0
Vladimir Iliev
Telerik team
answered on 16 Jul 2013, 02:00 PM
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!
0
Jean-Baptiste
Top achievements
Rank 1
answered on 19 Jul 2013, 04:38 PM
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!
0
Nikolay Rusev
Telerik team
answered on 22 Jul 2013, 06:59 AM
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!
0
DominionZA
Top achievements
Rank 1
answered on 07 Apr 2015, 08:18 AM
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")
                        )
                ))
0
Vladimir Iliev
Telerik team
answered on 09 Apr 2015, 07:29 AM
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!
 
0
Jean-Philippe
Top achievements
Rank 1
answered on 07 Jul 2015, 06:07 PM

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

0
Vladimir Iliev
Telerik team
answered on 09 Jul 2015, 06:11 AM
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!
 
Tags
Grid
Asked by
Fernando
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Fernando
Top achievements
Rank 1
Jonam
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Shawn
Top achievements
Rank 2
Jean-Baptiste
Top achievements
Rank 1
DominionZA
Top achievements
Rank 1
Jean-Philippe
Top achievements
Rank 1
Share this question
or