处理列过滤器服务器端事件
Contents
[
Hide
]
数据筛选可能是最常用的Excel功能之一,它允许您根据特定条件对数据进行筛选。经过筛选的数据仅显示满足条件的行,而隐藏不符合条件的行。
Aspose.Cells.GridWeb 组件通过其界面提供了执行数据筛选的能力。为了扩展其功能,Aspose.Cells.GridWeb 组件还提供了两个事件,可作为通过GridWeb UI进行筛选机制的回调。
处理应用列过滤器的服务器端事件
以下是两个主要事件的详细信息。
OnBeforeColumnFilter: 在对列应用筛选器之前触发。 OnAfterColumnFilter: 在对列应用筛选器后触发。
以下是 Aspose.Cells.GridWeb 组件的 ASPX 脚本,用于添加和分配上述事件。
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> |
这些事件可用于获取有关筛选过程的有用信息,例如用户为筛选在GridWeb UI上选择的列索引和值。以下是演示如何使用 OnBeforeColumnFilter 事件检索列索引和用户为筛选而选择的值的代码片段。
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; | |
} |
另一方面,如果需求是在应用筛选器后获取筛选行的数量,则可以使用如下所示的 OnAfterColumnFilter 事件。
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; | |
} |
查看有关 使用GridWeb事件 的介绍,以及如何处理这些事件的一些详细信息。