列フィルター サーバー側イベントの処理

列フィルター適用時のサーバー側イベントの処理

以下に詳述するように、2 つの主要なイベントがあります。

  1. OnBeforeColumnFilter: フィルターが列に適用される前に発生します。
  2. OnAfterColumnFilter: フィルターが列に適用された後に発生します。

前述のイベントを追加して割り当てる Aspose.Cells.GridWeb コンポーネントの ASPX スクリプトを次に示します。

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 で選択した列インデックスと値を取得する方法を示すスニペットです。

// 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 イベントを使用できます。

// 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;
}