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

[Solved] How to change default grid filter function without activating filter?

4 Answers 354 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Igor Stanek
Top achievements
Rank 1
Igor Stanek asked on 08 Jul 2011, 07:58 AM
Hello!

When a grid is filterable then users may open the filter dialog for a column by clicking on the filter "funnel" icon. In this filter dialog the default filter function is set to "is Equal".

Is it possible to change this default to other filter function, like "Contains" without applying/activating filter for all string based columns in given filter?

I like to set the default filter function to "Contains" so users don't need to select this in filter functions dropdown list in filter dialog.

Or is it possible to set grid filtering to have only this filter function available?

I am aware of similar forum threads asking similar (or same) question like:
http://www.telerik.com/community/forums/aspnet-mvc/grid/changing-the-default-set-up-in-the-telerik-grid-filter.aspx
http://www.telerik.com/community/forums/aspnet-mvc/grid/mvc-grid-setting-an-initial-filter-function-without-filtering.aspx
http://www.telerik.com/community/forums/aspnet-mvc/grid/how-can-i-change-the-default-filter-for-telerik-mvc-grid.aspx

but solutions given there either do not work (at least for me) - or given solutions also apply filter (which is not what I want) - second case.

btw, there is also unanswered StackOverflow question for this:
http://stackoverflow.com/questions/3681229/how-can-i-change-the-default-filter-for-telerik-mvc-grid

thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 08 Jul 2011, 11:35 AM
Hello Igor Stanek,

 The following should help:

<%: Html.Telerik().Grid(Model)
     .Name("Grid")
     .Sortable()
     .Filterable()
     .ClientEvents(e => e.OnLoad("onLoad"))
%>
 <script type="text/javascript">
   function onLoad() {
    $(this).find(".t-filter").click(function() {
        setTimeout(function() {
            $(".t-filter-operator").each(function() {
                $(this).val("substringof");
            }); 
        });
    });
   }
</script>

Greetings,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Igor Stanek
Top achievements
Rank 1
answered on 08 Jul 2011, 12:17 PM
Atanas, this works like a charm! 

Your support is just great!

thank you.
0
Örjan
Top achievements
Rank 1
answered on 25 Aug 2011, 04:10 PM
Does this really work if you are mixing string columns and integer columns? I think that it clears the selected default of the integer columns.
0
Kapil
Top achievements
Rank 1
answered on 02 Apr 2012, 05:21 PM
Hello Atanas,

I tried your solution but there are times where default filter option is "is equal to" instead of "starts with" (the default option that I want). Its just random.
function SitesGrid_onLoad() {
    $('#ABC').find(".t-filter").click(function () {
        setTimeout(function () {
            $(".t-filter-operator").each(function () {
                $(this).val("startswith");
            });
        });
    });
}
Why would that be happening that sometimes it changes the default option to starts with but other times it doesn't change the filter option to starts with.

Thanks
Tags
Grid
Asked by
Igor Stanek
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Igor Stanek
Top achievements
Rank 1
Örjan
Top achievements
Rank 1
Kapil
Top achievements
Rank 1
Share this question
or