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

How to exclude a column when using MVC Filtering

2 Answers 1511 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 07 Apr 2017, 01:51 PM

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 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 11 Apr 2017, 10:56 AM
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.
0
Randy
Top achievements
Rank 1
answered on 11 Apr 2017, 11:20 AM
Thank you. This works perfectly.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Randy
Top achievements
Rank 1
Share this question
or