列フィルターサーバーサイドイベントを処理する
Contents
[
Hide
]
データフィルタリングは、特定の条件に基づいてデータをフィルタリングできる、おそらく最も広く使用される Excel の機能です。フィルタリングされたデータは、条件を満たす行のみを表示し、条件を満たさない行は非表示にします。
Aspose.Cells.GridWeb コンポーネントは、そのインターフェイスを使用してデータフィルタリングを行う機能を提供します。Aspose.Cells.GridWeb コンポーネントは、GridWeb UI を介したフィルタリング機構へのコールバックとして機能する 2 つのイベントも提供します。
列フィルターの適用にサーバーサイドイベントを処理する
以下に詳細が記載されている2つの主要なイベントがあります。
- 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; | |
} |
これらのイベントの扱い方についての詳細や、すべてのWorking with GridWeb Eventsに関する導入情報をチェックしてください。