Skip to content

Commit 5423708

Browse files
kendo-botKB Bot
andauthored
Added new kb article grid-autoexpand-filter-section-column-menu (#3407)
Co-authored-by: KB Bot <kb-bot@telerik.com>
1 parent f1e4751 commit 5423708

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Automatically Expand Filter Section in Grid Column Menu
3+
description: Learn how to auto-expand the filter section when opening the column menu in TelerikGrid.
4+
type: how-to
5+
page_title: Automatically Expand Filter Section in Grid Column Menu
6+
meta_title: Autoexpand Filter Section in Grid Column Menu
7+
slug: grid-kb-autoexpand-filter-section-column-menu
8+
tags: grid, column-menu, filter
9+
res_type: kb
10+
ticketid: 1705448
11+
---
12+
13+
## Environment
14+
15+
<table>
16+
<tbody>
17+
<tr>
18+
<td>Product</td>
19+
<td>Grid for Blazor</td>
20+
</tr>
21+
</tbody>
22+
</table>
23+
24+
## Description
25+
26+
I want the filter section of the [column menu](slug:grid-column-menu) in the [TelerikGrid](slug:grid-overview) to automatically open when a user opens the column menu.
27+
28+
## Solution
29+
30+
To auto-expand the filter section, use JavaScript interop to simulate a click on the filter header when the column menu is opened. Below is a runnable example:
31+
32+
````Razor
33+
@inject IJSRuntime JSRuntime
34+
35+
<TelerikGrid Data="@GridData"
36+
Pageable="true"
37+
PageSize="5"
38+
FilterMode="@GridFilterMode.FilterMenu"
39+
Sortable="true"
40+
ShowColumnMenu="true">
41+
<GridColumns>
42+
<GridColumn Field="@(nameof(SampleData.Id))" Width="80px" />
43+
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Groupable="false" />
44+
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
45+
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
46+
</GridColumns>
47+
</TelerikGrid>
48+
49+
<script>
50+
window.initColumnMenuAutoClick = function () {
51+
// Select all column menu buttons in the grid header
52+
const menuButtons = document.querySelectorAll(".k-grid .k-header .k-grid-column-menu");
53+
54+
menuButtons.forEach(btn => {
55+
btn.addEventListener("click", () => {
56+
// Wait for the popup animation (adjust timeout if needed)
57+
setTimeout(() => {
58+
const items = document.querySelectorAll(
59+
".k-column-menu .k-columnmenu-item-wrapper .k-columnmenu-item"
60+
);
61+
62+
items[3].click();
63+
}, 150); // Adjust if animation is slower/faster
64+
});
65+
});
66+
};
67+
68+
</script>
69+
70+
@code {
71+
protected override async Task OnAfterRenderAsync(bool firstRender)
72+
{
73+
if (firstRender)
74+
{
75+
await Task.Delay(500); // Ensure the grid is fully rendered
76+
await JSRuntime.InvokeVoidAsync("initColumnMenuAutoClick");
77+
}
78+
}
79+
80+
private IEnumerable<SampleData> GridData = Enumerable.Range(1, 30).Select(x => new SampleData
81+
{
82+
Id = x,
83+
Name = "name " + x,
84+
Team = "team " + x % 5,
85+
HireDate = DateTime.Now.AddDays(-x).Date
86+
});
87+
88+
public class SampleData
89+
{
90+
public int Id { get; set; }
91+
public string Name { get; set; }
92+
public string Team { get; set; }
93+
public DateTime HireDate { get; set; }
94+
}
95+
}
96+
````
97+
98+
## See Also
99+
100+
* [Grid Documentation](slug:grid-overview)
101+
* [Column Menu Documentation](slug:grid-column-menu)

0 commit comments

Comments
 (0)