Skip to content

Added new kb article grid-display-active-filters-in-excel-like-filtering #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: Display Active Filters in Excel-Like Filtering
description: Learn how to show the filtered columns along with their specific values above a RadGrid control dynamically.
type: how-to
page_title: Display Active Filters in Excel-Like Filtering
slug: grid-display-active-filters-in-excel-like-filtering
tags: radgrid, asp.net ajax, filtering, display, columns, values
res_type: kb
ticketid: 1672360
---

## Environment

<table>
<tbody>
<tr>
<td>Product</td>
<td>RadGrid for ASP.NET AJAX</td>
</tr>
<tr>
<td>Version</td>
<td>All</td>
</tr>
</tbody>
</table>

## Description

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.

This knowledge-base article also answers the following questions:
- How can I show the active filters of a RadGrid?
- What method can I use to display the filtered columns and their values in RadGrid?
- Is it possible to list the current filters applied to a RadGrid above it?

## Solution

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:

1. Handle the `ItemCommand` event of the RadGrid.
2. Loop through the columns to check which ones have filters applied.
3. Retrieve the selected checkbox values for each column with Excel-like filtering.

````C#
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.HeaderContextMenuFilterCommandName)
{
foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
{
string[] filterValues = column.ListOfFilterValues;

if (filterValues != null && filterValues.Length > 0)
{
string columnName = column.UniqueName;
string selectedValues = string.Join(", ", filterValues);

// Update your display control accordingly
Response.Write("Column: " + columnName + ", Selected Values: " + selectedValues);
}
}
}
}
````

## See Also

- [RadGrid Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/overview)
- [Excel-like Filtering](https://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/excel-like-filtering/defaultcs.aspx)