Filter Specification - reuse

2 posts, 0 answers
  1. Fred
    Fred avatar
    4 posts
    Member since:
    Jan 2017

    Posted 26 Jan 2017 Link to this post

    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
  2. Niko
    Admin
    Niko avatar
    404 posts

    Posted 30 Jan 2017 Link to this post

    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.
Back to Top