|
| 1 | +--- |
| 2 | +title: Only one filter option in FilterMenu |
| 3 | +description: How to leave Only one filter option in FilterMenu |
| 4 | +type: how-to |
| 5 | +page_title: Only one filter option in FilterMenu |
| 6 | +slug: grid-kb-only-one-filtermenu-option |
| 7 | +position: |
| 8 | +tags: |
| 9 | +ticketid: 1451755 |
| 10 | +res_type: kb |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Grid for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | + |
| 24 | +## Description |
| 25 | +I want simple filtering options in the filter menu - both for my uses and my backend. How do I remove the extra conditions so it behaves like the filter row and does not have extra and/or operators |
| 26 | + |
| 27 | +>caption Before and after results |
| 28 | +
|
| 29 | + |
| 30 | + |
| 31 | +## Solution |
| 32 | +You can use CSS to hide the elements that provide the and/or secondary conditions: |
| 33 | + |
| 34 | +>caption Hide And/Or filter options in FilterMenu |
| 35 | +
|
| 36 | +````CSHTML |
| 37 | +@* These CSS rules hide the second component wrappers *@ |
| 38 | +
|
| 39 | +<style> |
| 40 | + .k-filter-menu-container .k-widget.k-dropdown, |
| 41 | + .k-filter-menu-container .k-state-empty:nth-of-type(2n), |
| 42 | + .k-filter-menu-container .k-datepicker:nth-of-type(2n), |
| 43 | + .k-filter-menu-container .k-numerictextbox:nth-of-type(2n) { |
| 44 | + display: none; |
| 45 | + } |
| 46 | +
|
| 47 | + .k-filter-menu-container .k-widget.k-dropdown:first-of-type { |
| 48 | + display: block; |
| 49 | + } |
| 50 | +</style> |
| 51 | +
|
| 52 | +<TelerikGrid Data=@GridData FilterMode="Telerik.Blazor.GridFilterMode.FilterMenu" |
| 53 | + Pageable="true" Height="400px"> |
| 54 | + <GridColumns> |
| 55 | + <GridColumn Field=@nameof(Employee.Name) /> |
| 56 | + <GridColumn Field=@nameof(Employee.AgeInYears) Title="Age" /> |
| 57 | + <GridColumn Field=@nameof(Employee.HireDate) Title="Hire Date" /> |
| 58 | + <GridColumn Field=@nameof(Employee.IsOnLeave) Title="On Vacation" /> |
| 59 | + </GridColumns> |
| 60 | +</TelerikGrid> |
| 61 | +
|
| 62 | +@code { |
| 63 | + public List<Employee> GridData { get; set; } |
| 64 | +
|
| 65 | + protected override void OnInitialized() |
| 66 | + { |
| 67 | + GridData = new List<Employee>(); |
| 68 | + var rand = new Random(); |
| 69 | + for (int i = 0; i < 100; i++) |
| 70 | + { |
| 71 | + GridData.Add(new Employee() |
| 72 | + { |
| 73 | + EmployeeId = i, |
| 74 | + Name = "Employee " + i.ToString(), |
| 75 | + AgeInYears = rand.Next(10, 80), |
| 76 | + HireDate = DateTime.Now.Date.AddDays(rand.Next(-20, 20)), |
| 77 | + IsOnLeave = i % 3 == 0 |
| 78 | + }); |
| 79 | + } |
| 80 | + } |
| 81 | +
|
| 82 | + public class Employee |
| 83 | + { |
| 84 | + public int? EmployeeId { get; set; } |
| 85 | + public string Name { get; set; } |
| 86 | + public int? AgeInYears { get; set; } |
| 87 | + public DateTime HireDate { get; set; } |
| 88 | + public bool IsOnLeave { get; set; } |
| 89 | + } |
| 90 | +} |
| 91 | +```` |
0 commit comments