|
| 1 | +--- |
| 2 | +title: Display Active Filters in Excel-Like Filtering |
| 3 | +description: Learn how to show the filtered columns along with their specific values above a RadGrid control dynamically. |
| 4 | +type: how-to |
| 5 | +page_title: Display Active Filters in Excel-Like Filtering |
| 6 | +slug: grid-display-active-filters-in-excel-like-filtering |
| 7 | +tags: radgrid, asp.net ajax, filtering, display, columns, values |
| 8 | +res_type: kb |
| 9 | +ticketid: 1672360 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | +<tbody> |
| 16 | +<tr> |
| 17 | +<td>Product</td> |
| 18 | +<td>RadGrid for ASP.NET AJAX</td> |
| 19 | +</tr> |
| 20 | +<tr> |
| 21 | +<td>Version</td> |
| 22 | +<td>All</td> |
| 23 | +</tr> |
| 24 | +</tbody> |
| 25 | +</table> |
| 26 | + |
| 27 | +## Description |
| 28 | + |
| 29 | +I need to display which columns in a RadGrid are being filtered and what the specific filter values are for each column. The goal is to show this information in a label or a similar control above the RadGrid to let users know what filters are currently applied. |
| 30 | + |
| 31 | +This knowledge-base article also answers the following questions: |
| 32 | +- How can I show the active filters of a RadGrid? |
| 33 | +- What method can I use to display the filtered columns and their values in RadGrid? |
| 34 | +- Is it possible to list the current filters applied to a RadGrid above it? |
| 35 | + |
| 36 | +## Solution |
| 37 | + |
| 38 | +To display the filtered columns and their respective values above a RadGrid control, iterate through the columns, retrieve the details of the applied filters, and then display this information: |
| 39 | + |
| 40 | +1. Handle the `ItemCommand` event of the RadGrid. |
| 41 | +2. Loop through the columns to check which ones have filters applied. |
| 42 | +3. Retrieve the selected checkbox values for each column with Excel-like filtering. |
| 43 | + |
| 44 | +````C# |
| 45 | +protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) |
| 46 | +{ |
| 47 | + if (e.CommandName == RadGrid.HeaderContextMenuFilterCommandName) |
| 48 | + { |
| 49 | + foreach (GridColumn column in RadGrid1.MasterTableView.Columns) |
| 50 | + { |
| 51 | + string[] filterValues = column.ListOfFilterValues; |
| 52 | + |
| 53 | + if (filterValues != null && filterValues.Length > 0) |
| 54 | + { |
| 55 | + string columnName = column.UniqueName; |
| 56 | + string selectedValues = string.Join(", ", filterValues); |
| 57 | + |
| 58 | + // Update your display control accordingly |
| 59 | + Response.Write("Column: " + columnName + ", Selected Values: " + selectedValues); |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +```` |
| 65 | + |
| 66 | +## See Also |
| 67 | + |
| 68 | +- [RadGrid Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/overview) |
| 69 | +- [Excel-like Filtering](https://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/excel-like-filtering/defaultcs.aspx) |
0 commit comments