列フィルターサーバーサイドイベントを処理する

列フィルターの適用にサーバーサイドイベントを処理する

以下に詳細が記載されている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>

これらのイベントは、列インデックスやGridWeb UIでフィルタリング用にユーザーが選択した値など、フィルタリングプロセスに関する有用な情報を取得するために使用できます。以下は、OnBeforeColumnFilterイベントの使用例と、列インデックスおよびフィルタリングのためにユーザーが選択した値を取得するコードスニペットです。

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