Skip to content

Commit c4c67c4

Browse files
authored
kb(Grid): Update single filter menu option CSS (#3383)
1 parent 6d68ba7 commit c4c67c4

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

knowledge-base/grid-kb-only-one-filtermenu-option.md

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ page_title: Only one filter option in FilterMenu
66
slug: grid-kb-only-one-filtermenu-option
77
position:
88
tags:
9-
ticketid: 1451755, 1551245
9+
ticketid: 1451755, 1551245, 1705873
1010
res_type: kb
1111
---
1212

1313
## Environment
14+
1415
<table>
1516
<tbody>
1617
<tr>
1718
<td>Product</td>
18-
<td>Grid for Blazor</td>
19+
<td>Grid for Blazor, <br /> TreeList for Blazor</td>
1920
</tr>
2021
</tbody>
2122
</table>
2223

2324

2425
## Description
26+
2527
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?
2628

2729
>caption Before and after results
@@ -33,79 +35,59 @@ I want simple filtering options in the Grid filter menu - both for my uses and m
3335
There are two options:
3436

3537
* 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**:
38+
* 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.
3739

38-
<div class="skip-repl"></div>
39-
````CSS
40-
<style>
41-
/* UI for Blazor 3.0+ */
42-
.k-filter-menu-container > span:nth-child(n+3) {
43-
display: none;
44-
}
45-
/* UI for Blazor 2.30- */
46-
.k-filter-menu-container > div > :nth-child(n+3) {
47-
display: none;
48-
}
49-
</style>
40+
````CSS.skip-repl
41+
.k-filter-menu-container > .k-button-group,
42+
.k-filter-menu-container > span:nth-child(n+3) {
43+
display: none;
44+
}
5045
````
5146

52-
>caption Hide And/Or filter options in the Grid/TreeList FilterMenu with CSS
47+
>caption Hide And/Or ButtonGroup and second filter option in the Grid/TreeList FilterMenu with CSS
5348
5449
````RAZOR
55-
@* Hide the secondary filter interface with CSS *@
56-
5750
<TelerikGrid Data="@GridData"
58-
Pageable="true"
59-
PageSize="5"
60-
Sortable="true"
6151
FilterMode="GridFilterMode.FilterMenu">
6252
<GridColumns>
63-
<GridColumn Field=@nameof(Product.Name) Title="Product Name" />
64-
<GridColumn Field=@nameof(Product.Price) Title="Price" />
65-
<GridColumn Field=@nameof(Product.ReleaseDate) Title="Release Date" />
66-
<GridColumn Field=@nameof(Product.Discontinued) Title="Discontinued" />
53+
<GridColumn Field="@nameof(Product.Name)" Title="Product" />
54+
<GridColumn Field="@nameof(Product.Price)" />
55+
<GridColumn Field="@nameof(Product.ReleaseDate)" Title="Release Date" DisplayFormat="{0:d}" />
56+
<GridColumn Field="@nameof(Product.Discontinued)" />
6757
</GridColumns>
6858
</TelerikGrid>
6959
7060
<style>
71-
72-
/* UI for Blazor 3.0+ */
61+
.k-filter-menu-container > .k-button-group,
7362
.k-filter-menu-container > span:nth-child(n+3) {
7463
display: none;
7564
}
76-
77-
/* UI for Blazor 2.30- */
78-
.k-filter-menu-container > div > :nth-child(n+3) {
79-
display: none;
80-
}
81-
8265
</style>
8366
8467
@code {
85-
List<Product> GridData { get; set; }
68+
private List<Product> GridData { get; set; } = new();
8669
8770
protected override void OnInitialized()
8871
{
89-
GridData = new List<Product>();
90-
var rnd = new Random();
72+
var rnd = Random.Shared;
9173
92-
for (int i = 1; i <= 15; i++)
74+
for (int i = 1; i <= 7; i++)
9375
{
9476
GridData.Add(new Product()
9577
{
96-
ID = i,
97-
Name = "Product " + i.ToString(),
98-
Price = (decimal)rnd.Next(1, 100),
99-
ReleaseDate = new DateTime(rnd.Next(2020, 2023), rnd.Next(1, 13), rnd.Next(1, 28)),
78+
Id = i,
79+
Name = $"Product {i}",
80+
Price = rnd.Next(1, 100) * 1.23m,
81+
ReleaseDate = DateTime.Today.AddDays(-rnd.Next(1, 3650)),
10082
Discontinued = i % 4 == 0
10183
});
10284
}
10385
}
10486
10587
public class Product
10688
{
107-
public int ID { get; set; }
108-
public string Name { get; set; }
89+
public int Id { get; set; }
90+
public string Name { get; set; } = string.Empty;
10991
public decimal Price { get; set; }
11092
public DateTime ReleaseDate { get; set; }
11193
public bool Discontinued { get; set; }

0 commit comments

Comments
 (0)