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

Filter Specification - reuse

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 26 Jan 2017, 05:07 PM

How can I avoid the copy/paste technique shown below in which certain columns of my grid need to have the Is Null, Is Not Null and other built-in filters removed but allow other columns in that same grid to use Is Null, Is Not Null, etc. ?

I do NOT want to do this GLOBALLY for the entire Grid, just certain columns (that are required when they are input into the system, so null and not null are not wanted or needed by the customer).

What I have works, but it seems terribly inefficient to have to physically repeat all that .Filterable() information for each column that needs it. 

.Columns(c =>
        {
            c.Bound(q => q.FirstName)
                .Filterable(filterable => filterable
                    .Extra(false)
                    .Operators(operators => operators
                        .ForString(str => str.Clear()
                            .IsEqualTo("Is equal to")
                            .IsNotEqualTo("Is not equal to")
                            .Contains("Contains")
                            .DoesNotContain("Does not contain")
                            .StartsWith("Starts with")
                            .EndsWith("Ends with")
                        ) // ForString
                    ) // Operators
                ); // Filterable
 
            c.Bound(q => q.LastName)
                .Filterable(filterable => filterable
                    .Extra(false)
                    .Operators(operators => operators
                        .ForString(str => str.Clear()
                            .IsEqualTo("Is equal to")
                            .IsNotEqualTo("Is not equal to")
                            .Contains("Contains")
                            .DoesNotContain("Does not contain")
                            .StartsWith("Starts with")
                            .EndsWith("Ends with")
                        ) // ForString
                    ) // Operators
                ); // Filterable
 
            c.Bound(q => q.Email)
                .Filterable(filterable => filterable
                    .Extra(false)
                    .Operators(operators => operators
                        .ForString(str => str.Clear()
                            .IsEqualTo("Is equal to")
                            .IsNotEqualTo("Is not equal to")
                            .Contains("Contains")
                            .DoesNotContain("Does not contain")
                            .StartsWith("Starts with")
                            .EndsWith("Ends with")
                        ) // ForString
                    ) // Operators
                ); // Filterable

1 Answer, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 30 Jan 2017, 12:20 PM

Hello Fred,

The `Filterable` method of a column builder expects an Action<Kendo.Mvc.UI.Fluent.GridBoundColumnFilterableBuilder> parameter. You just need to provide a reference to such an Action. This corresponds to any method with the following signature:

void ColumnFilterable(Kendo.Mvc.UI.Fluent.GridBoundColumnFilterableBuilder f)

Therefore any such method will do as long as it is accessible from the View, which is defined by your object-oriented design. I would go with a public static method:

public static void StringFilterable(Kendo.Mvc.UI.Fluent.GridBoundColumnFilterableBuilder filterable)
{
    filterable
        .Extra(false)
        .Operators(operators => operators
            .ForString(str => str.Clear()
                .IsEqualTo("Is equal to")
                .IsNotEqualTo("Is not equal to")
                .Contains("Contains")
                .DoesNotContain("Does not contain")
                .StartsWith("Starts with")
                .EndsWith("Ends with")
            ) // ForString
        ); // Operators
}

Then in the setup you could just mention the defined method:

.Filterable(TelerikMVC.Filters.StringFilterable);

Hope this helps.

Regards,
Niko
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Answers by
Niko
Telerik team
Share this question
or