列フィルター サーバー側イベントの処理
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> |
これらのイベントを使用して、フィルターを適用する必要がある列のインデックスや値など、フィルター処理に関する有用な情報を取得できます。以下は、OnBeforeColumnFilter イベントを使用して、ユーザーがフィルタリングのために GridWeb UI で選択した列インデックスと値を取得する方法を示すスニペットです。
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 イベントの操作これらのイベントを処理する方法の詳細とともに。