Handle Column Filter Server Side Events
Contents
[
Hide
]
Data filtering is probably the most widely used Excel feature that allows you to filter the data based on a specific criteria. Filtered data displays only the rows that meet the condition by hiding the rows that do not fulfill the criteria.
Aspose.Cells.GridWeb component provides the ability to perform the data filtering using its interface. In order to extend its capabilities, Aspose.Cells.GridWeb component also provides two events that can serve as callback to the filtering mechanism done through the GridWeb UI.
Handling Server Side Event on Applying Column Filter
There are two main events as detailed below.
- OnBeforeColumnFilter: Fires before the filter is going to be applied on a column.
- OnAfterColumnFilter: Fires after the filter has been applied on a column.
Here is the ASPX script of the Aspose.Cells.GridWeb component to add and assign the aforementioned events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
<acw:GridWeb ID="GridWeb1" runat="server" | |
OnBeforeColumnFilter="GridWeb1_BeforeColumnFilter" | |
OnAfterColumnFilter="GridWeb1_AfterColumnFilter"> | |
</acw:GridWeb> |
These events can be used to get useful information about the filtering process such as column index and value on which filter has to be applied. Following is the snippet demonstrating the usage of OnBeforeColumnFilter event to retrieve the column index and value which user has selected on GridWeb UI for filtering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
protected void GridWeb1_BeforeColumnFilter(object sender, RowColumnEventArgs e) | |
{ | |
// Display the column index and filter applied | |
string msg = "[Column Index]: " + (e.Num) + ", [Filter Value]: " + e.Argument; | |
Label1.Text = msg; | |
} |
On the other hand, if the requirement is to get number of filtered rows after the filter has been applied then you can use the OnAfterColumnFilter event as demonstrated below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
protected void GridWeb1_AfterColumnFilter(object sender, RowColumnEventArgs e) | |
{ | |
string hidden = ""; | |
int headrow = 0; | |
int maxrow = GridWeb1.WorkSheets[0].Cells.MaxRow; | |
int count = 0; | |
// Iterate all worksheet rows to find out filtered rows | |
for (int i = headrow + 1; i <= maxrow; i++) | |
{ | |
if (GridWeb1.WorkSheets[0].Cells.Rows[i].Hidden) | |
{ | |
hidden += "-" + (i + 1); | |
} | |
else | |
{ | |
count++; | |
} | |
} | |
// Display hidden rows and visible rows count | |
string msg = "[Hidden Rows]: " + hidden + " [Visible Rows]: " + count; | |
Label1.Text = msg; | |
} |
Check introduction to all Working with GridWeb Events along with some details on how to handle these event.