← 返回所有博客文章

Spread for ASP.NET 表格控件提供了内置的分组功能。允许用户拖拽列头到分组区域进行分组。分组行头默认显示分组的列索引及分组的唯一值。

本篇文章将讨论如何定制分组行头文本来显示分组中包含的行数。

实现方法

这个用例实现起来十分的简单。我们所要做的是循环表单中所有非空行,通过 IsGroup 方法判断是否为分组行,如果是,则获取其相关信息:

  1: private void CalculateGroups(object sender)
  2: {
  3:    FarPoint.Web.Spread.FpSpread ss = (FarPoint.Web.Spread.FpSpread)sender;
  4:    FarPoint.Web.Spread.Model.GroupDataModel gm;
  5:    int total;
  6:    int column = 0;
  7:    int y = 0;
  8:    gm = (FarPoint.Web.Spread.Model.GroupDataModel)ss.ActiveSheetView.DataModel;
  9:   
 10:    for (int i = 0; i < ss.ActiveSheetView.NonEmptyRowCount; i++)
 11:    {
 12:      if (gm.IsGroup(i))
 13:       {
 14:         FarPoint.Web.Spread.Model.Group g;
 15:         g = gm.GetGroup(i);
 16:         g.Expanded = false;
 17:         total = 0;
 18:         total = g.Rows.Count;
 19:         column = g.Column;
 20:   
 21:         string s = gm.TargetModel.GetValue(getRow(g), column).ToString();
 22:         s = column.ToString() + ":" + s;
 23:         g.Text = s + " (" + total.ToString() + ")";
 24:       }
 25:    }
 26: }
 27:   
 28: int getRow(FarPoint.Web.Spread.Model.Group group)
 29: {
 30:   if (group.Rows[0] is FarPoint.Web.Spread.Model.Group) return getRow(group.Rows[0] as FarPoint.Web.Spread.Model.Group);
 31:       return (int)group.Rows[0];
 32: }

 

效果图:

Output

Demo 下载:

VS2010 + Framework + C# + Spread for ASP.NET 7.0V2 点击下载

VS2010 + Framework + VB.NET + Spread for ASP.NET 7.0V2 点击下载