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

[Solved] OR Filter

5 Answers 226 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.
ashish
Top achievements
Rank 1
ashish asked on 30 Nov 2010, 02:59 PM
Dear TeamMember,

We are working on ASP.Net MVC application using Telerik grid.
By default AND filter is available for filtering.
Is there any workaround to Modify it so that User can Select AND/OR condition for filtering a particular column.
i.e. A column named as Color can be filtered like :
"red"
OR
"green"

Thanks,
Ashish

5 Answers, 1 is accepted

Sort by
0
Rick
Top achievements
Rank 1
answered on 22 Jan 2011, 02:15 AM
I also would like to see this functionality.

As a workaround I can do the OR filter server-side before passing my IEnumerable<T> to the grid model, but this isn't very flexible.
0
Ammar
Top achievements
Rank 1
answered on 01 Apr 2011, 05:29 AM
How did you achieve "OR" filtering with Telerik MVC Grid. A code snippet will be highly appreciated. Appreciate a quick reply.

Thanks,
Ammar
0
Raymond
Top achievements
Rank 1
answered on 18 Oct 2011, 08:06 PM
Anyone have a resolution on this? I'd like to see the functionality too.
0
Alex
Top achievements
Rank 1
answered on 09 Jul 2012, 03:24 PM
I'm interested in this too.  How do we create an OR filter option?
0
Stef Heyenrath
Top achievements
Rank 1
answered on 28 Nov 2012, 07:53 AM
I've the same question, see this page.

Currently I'm trying to build an AND/OR filter, it almost works, the missing functionality is that the AND or OR selection is not remembered after the grid is refreshed.

I keep you informed about the progress.

[update @ 3 December 2012]

Add this helper jquery function which replaces 'And' with a dropdownlist:
$(".GridFilter_Replace_And_By_AndOr .t-filter").click(function () {
    setTimeout(function () {
        var div = $('.t-filter-options, .t-group, .t-popup');
        var divHelpText = div.find(".t-filter-help-text:contains('And')");
 
        // Remove text
        divHelpText.text('');
 
        // Create select element and append this to divHelpText
        var s = $('<select />').attr("class", "andor_ddl");
        $('<option />', { value: '', text: 'And'}).appendTo(s);
        $('<option />', { value: 'or', text: 'Or' }).appendTo(s);
        divHelpText.append(s);
    });
});

And use this javascript client function in the 'OnDataBinding' in the grid:
function MyGrid_OnDataBinding(e) {
    var grid = $(this).data('tGrid');
    var filterBy = grid.filterBy;
 
    // Replace invalid OR filter (if present)
    // Example : ORUCode~startswith~'1'~or~ORUCode~startswith~'2'
    if (e != null && e.filteredColumns != null && e.filteredColumns.length > 0) {
        e.filteredColumns.forEach(function(filteredColumn) {
            filterBy = filterBy.replace("~and~" + filteredColumn.member + "~~'or'~and~", "~or~");
        });
 
        grid.filterBy = filterBy;
    }
}

And make sure that the function defined in the first step is executed for a specified column, like this:
columns.Bound(p => p.ORUCode).HeaderHtmlAttributes(new { @class = "GridFilter_Replace_And_By_AndOr" });

There is still the problem that the selected value "And" or "Or" in the dropdownlist is not remembered. I'm still working on that...
Tags
Grid
Asked by
ashish
Top achievements
Rank 1
Answers by
Rick
Top achievements
Rank 1
Ammar
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Stef Heyenrath
Top achievements
Rank 1
Share this question
or