How to exclude a column when using MVC Filtering

3 posts, 0 answers
  1. Randy
    Randy avatar
    75 posts
    Member since:
    Jul 2009

    Posted 07 Apr 2017 Link to this post

    I have a grid in an MVC environment. I have my filterable properties set up as follows:

              .Filterable(filterable => filterable
                    .Extra(false)
                    .Operators(operators => operators
                        .ForString(str => str.Clear()
                            .StartsWith("Starts with")
                            .IsEqualTo("Equal to")
                            .IsNotEqualTo("Not equal to")
                            .Contains("Contains")
                        )
                        .ForNumber(number => number.Clear()
                            .IsEqualTo("Equal to")
                            .IsNotEqualTo("Not equal to")
                            .IsGreaterThanOrEqualTo("Greater than or equal to")
                            .IsLessThanOrEqualTo("Less than or equal to")
                            .IsGreaterThan("Greater than")
                            .IsLessThan("Less than")
                        )
                        .ForDate(date => date.Clear()
                            .IsEqualTo("Equal to")
                            .IsNotEqualTo("Not equal to")
                            .IsGreaterThanOrEqualTo("Greater than or equal to")
                            .IsLessThanOrEqualTo("Less than or equal to")
                            .IsGreaterThan("Greater than")
                            .IsLessThan("Less than")
                        )
                    )
                )

     

    I have two questions:

    1) I have a column in my grid that I do not want filterable. How do I exclude just that one column?

    2) I am using these same filterable operators on all my grids in my app. Is there some way I can avoid repeating all this code for each grid and just provide some sort of reference to these defined operator values?

  2. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    995 posts

    Posted 11 Apr 2017 Link to this post

    Hello Randy,

    I confirm that both of the requirements can be achieved. Here is how:

    1) I have a column in my grid that I do not want filterable. How do I exclude just that one column?

    Set the Filterable property at column level and pass false. API reference:
    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.filterable

    .Columns(columns => {
      columns.Bound(e => e.City)
        .Width(200)
        .Filterable(false);
    })

    2) I am using these same filterable operators on all my grids in my app. Is there some way I can avoid repeating all this code for each grid and just provide some sort of reference to these defined operator values? 

    You can override the filter operators on all grids by setting them on the filter menu prototype as shown here:
    http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-filterable.operators

    Note that the target prototype is different dependent on the filterable mode - for the row, use FilterCell, for the column, use FilterMenu.

    For your convenience, your particular implementation will look like this:

    <script>
      kendo.ui.FilterMenu.fn.options.extra = false;
     
      kendo.ui.FilterMenu.fn.options.operators.number = {
        eq: "Equal to",
        neq: "Not equal to",
        gte: "Greater than or equal to",
        lte: "Less than or equal to",
        gt: "Greater than",
        lt: "Less than"
      };
     
      kendo.ui.FilterMenu.fn.options.operators.string = {
        eq: "Equal to",
        neq: "Not equal to",
        startswith: "Starts with",
        contains: "Contains"
      };
     
      kendo.ui.FilterMenu.fn.options.operators.date = {
        eq: "Equal to",
        neq: "Not equal to",
        gte: "Greater than or equal to",
        lte: "Less than or equal to",
        gt: "Greater than",
        lt: "Less than"
      };
    </script>

    And in the grid definition, you can only call Filterable() on the Kendo UI Grid level and the settings declared in the JavaScript above will automatically give you the desired outcome.

    Kind Regards,
    Alex Hajigeorgieva
    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.
  3. Randy
    Randy avatar
    75 posts
    Member since:
    Jul 2009

    Posted 11 Apr 2017 in reply to Alex Hajigeorgieva Link to this post

    Thank you. This works perfectly.
Back to Top