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

[Solved] How to reduce the filter options for a specific column ?

2 Answers 154 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.
Stef Heyenrath
Top achievements
Rank 1
Stef Heyenrath asked on 01 Feb 2012, 11:21 AM
For ASP.NET Ajax, this can be done using this.

For changing all filter options for a complete grid, this can be found here.

But how do I remove certain filters for a specific column ?
Like the "Code" column should only contain the string filter "Contains".
But the "Name" column should contain all string filters.

2 Answers, 1 is accepted

Sort by
0
Stef Heyenrath
Top achievements
Rank 1
answered on 01 Feb 2012, 05:11 PM
Found the answer here.

My solution is like this:

GRID:
columns.Bound(o => o.MRUCode).HeaderHtmlAttributes(new { @class = "FilterOnlyOn_Contains" });

JavaScript Code:
$(".FilterOnlyOn_Contains .t-filter").click(function () {
    setTimeout(function () {
        // Remove all existing options and add 'Contains'
        var filterOptions1 = $(".t-filter-operator").first();
        filterOptions1.empty();
        filterOptions1.append($("<option />").val("substringof").text("Contains"));
         
        // Remove second part (options + text + input)
        var filterOptions2 = $(".t-filter-operator").last();
        filterOptions2.hide();
        $(".t-filter-help-text").text("");
        $("input[type=text]").last().hide();
    });
});

And it looks like this.
[IMG]http://img3.imageshack.us/img3/1485/telerikfilter.png[/IMG]






0
Alex
Top achievements
Rank 1
answered on 22 Mar 2012, 04:05 PM
This was helpful. I used your idea and then organized the adjusting functions to be reusable between different grids.  I only needed to remove the 2nd input option from the filter.

Grid:
columns.ForeignKey( ... ).HeaderHtmlAttributes(new { @class = "GridFilterSingleInput" });

Javascript:

function MyGrid_onLoad() {
     tgHelper.filtersCustomize.call(this);
}
 
//Telerik Grid helper object
var tgHelper = {
    filtersSingleInput: TelerikGridAllFiltersSingleInput,
    filtersCustomize: TelerikGridFiltersCustomize
};
 
//will set all filters with only one input option
function TelerikGridAllFiltersSingleInput() {
    $(this).find("th .t-grid-filter").click(function () {
        setTimeout(function () {
            $(".t-filter-help-text:contains('And')").nextUntil(".t-button").andSelf().remove();
        }, 10);
    });
}
 
//will set all filters with only one input option as specified by GridFilterSingleInput  class in the header
function TelerikGridFiltersCustomize() {
    $(this).find("th .t-grid-filter").click(function () {
        setTimeout($.proxy(function() { //use .proxy to pass the parent header tag into the function
            var secondItem = $(".t-filter-help-text:contains('And')").nextUntil(".t-button").andSelf();
            if ($(this).hasClass("GridFilterSingleInput"))
                secondItem.hide();
            else
                secondItem.show(); //need a reset if hidden prior
        }, $(this).parent("th")), 10);
    });
}
Tags
Grid
Asked by
Stef Heyenrath
Top achievements
Rank 1
Answers by
Stef Heyenrath
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Share this question
or