Skip to content

Commit 220e8c3

Browse files
github-actions[bot]dimodiDimo Dimov
authored
Merge grid-kb-update-748 into production (#749)
* docs: Update Grid FilterMenu KB * refactor code example * refactor code example 2 * refactor code example 3 * refactor code example 4 Co-authored-by: Dimo Dimov <[email protected]> Co-authored-by: Dimo Dimov <[email protected]>
1 parent 1ac8c25 commit 220e8c3

File tree

1 file changed

+55
-40
lines changed

1 file changed

+55
-40
lines changed
Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: Only one filter option in FilterMenu
3-
description: How to leave Only one filter option in FilterMenu.
3+
description: How to leave only one filter option in the Grid FilterMenu. Applies to the TreeList too.
44
type: how-to
55
page_title: Only one filter option in FilterMenu
66
slug: grid-kb-only-one-filtermenu-option
77
position:
88
tags:
9-
ticketid: 1451755
9+
ticketid: 1451755, 1551245
1010
res_type: kb
1111
---
1212

@@ -22,7 +22,7 @@ res_type: kb
2222

2323

2424
## 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
25+
I want simple filtering options in the Grid 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?
2626

2727
>caption Before and after results
2828
@@ -32,66 +32,81 @@ I want simple filtering options in the filter menu - both for my uses and my bac
3232

3333
There are two options:
3434

35-
* A [custom filter template]({%slug grid-templates-filter%}) provides full flexibility, including on building the filter descriptor. This is the approach we recommend for such a scenario.
35+
* Use a [custom filter template]({%slug grid-templates-filter%}). It provides full flexibility over the interface and building the filter descriptor.
36+
* Use custom CSS to [override the theme]({%slug themes-override%}) and hide the elements that provide the and/or secondary conditions. The example below demonstrates this approach. Note that **the required CSS is different for different UI for Blazor versions**:
3637

37-
* You can use CSS to hide the elements that provide the and/or secondary conditions. An example of this is provided below. Note that the CSS rules used by the grid rendering may change and that these rules will also target all the grids on the page.
38+
<div class="skip-repl"></div>
3839

39-
>caption Hide And/Or filter options in FilterMenu with CSS
40+
/* UI for Blazor 3.0+ */
41+
.k-filter-menu-container > span:nth-child(n+3) {
42+
display: none;
43+
}
44+
45+
/* UI for Blazor 2.30- */
46+
.k-filter-menu-container > div > :nth-child(n+3) {
47+
display: none;
48+
}
49+
50+
>caption Hide And/Or filter options in the Grid/TreeList FilterMenu with CSS
4051
4152
````CSHTML
42-
@* These CSS rules hide the second component wrappers *@
53+
@* Hide the secondary filter interface with CSS *@
54+
55+
<TelerikGrid Data="@GridData"
56+
Pageable="true"
57+
PageSize="5"
58+
Sortable="true"
59+
FilterMode="GridFilterMode.FilterMenu">
60+
<GridColumns>
61+
<GridColumn Field=@nameof(Product.Name) Title="Product Name" />
62+
<GridColumn Field=@nameof(Product.Price) Title="Price" />
63+
<GridColumn Field=@nameof(Product.ReleaseDate) Title="Release Date" />
64+
<GridColumn Field=@nameof(Product.Discontinued) Title="Discontinued" />
65+
</GridColumns>
66+
</TelerikGrid>
4367
4468
<style>
45-
.k-filter-menu-container .k-dropdown,
46-
.k-filter-menu-container .k-state-empty:nth-of-type(2n),
47-
.k-filter-menu-container .k-textbox:nth-of-type(2n),
48-
.k-filter-menu-container .k-datepicker:nth-of-type(2n+1),
49-
.k-filter-menu-container .k-numerictextbox:nth-of-type(2n) {
69+
70+
/* UI for Blazor 3.0+ */
71+
.k-filter-menu-container > span:nth-child(n+3) {
5072
display: none;
5173
}
5274
53-
.k-filter-menu-container .k-dropdown:first-of-type {
54-
display: block;
55-
}
56-
</style>
75+
/* UI for Blazor 2.30- */
76+
.k-filter-menu-container > div > :nth-child(n+3) {
77+
display: none;
78+
}
5779
58-
<TelerikGrid Data=@GridData FilterMode="Telerik.Blazor.GridFilterMode.FilterMenu"
59-
Pageable="true" Height="400px">
60-
<GridColumns>
61-
<GridColumn Field=@nameof(Employee.Name) />
62-
<GridColumn Field=@nameof(Employee.AgeInYears) Title="Age" />
63-
<GridColumn Field=@nameof(Employee.HireDate) Title="Hire Date" />
64-
<GridColumn Field=@nameof(Employee.IsOnLeave) Title="On Vacation" />
65-
</GridColumns>
66-
</TelerikGrid>
80+
</style>
6781
6882
@code {
69-
public List<Employee> GridData { get; set; }
83+
List<Product> GridData { get; set; }
7084
7185
protected override void OnInitialized()
7286
{
73-
GridData = new List<Employee>();
74-
var rand = new Random();
75-
for (int i = 0; i < 100; i++)
87+
GridData = new List<Product>();
88+
var rnd = new Random();
89+
90+
for (int i = 1; i <= 15; i++)
7691
{
77-
GridData.Add(new Employee()
92+
GridData.Add(new Product()
7893
{
79-
EmployeeId = i,
80-
Name = "Employee " + i.ToString(),
81-
AgeInYears = rand.Next(10, 80),
82-
HireDate = DateTime.Now.Date.AddDays(rand.Next(-20, 20)),
83-
IsOnLeave = i % 3 == 0
94+
ID = i,
95+
Name = "Product " + i.ToString(),
96+
Price = (decimal)rnd.Next(1, 100),
97+
ReleaseDate = new DateTime(rnd.Next(2020, 2023), rnd.Next(1, 13), rnd.Next(1, 28)),
98+
Discontinued = i % 4 == 0
8499
});
85100
}
86101
}
87102
88-
public class Employee
103+
public class Product
89104
{
90-
public int? EmployeeId { get; set; }
105+
public int ID { get; set; }
91106
public string Name { get; set; }
92-
public int? AgeInYears { get; set; }
93-
public DateTime HireDate { get; set; }
94-
public bool IsOnLeave { get; set; }
107+
public decimal Price { get; set; }
108+
public DateTime ReleaseDate { get; set; }
109+
public bool Discontinued { get; set; }
95110
}
96111
}
97112
````

0 commit comments

Comments
 (0)