Spread for ASP.NET基础教程-过滤

发布时间:2015/04/16 00:04 发布者:iceman

返回博客中心

表格控件 Spread 提供多种过滤方式,包括基本过滤、过滤条和类似于 Microsoft Excel 的过滤方式。基本过滤方式在 Spread for ASP.NET 7 之前提供,在本次发布的版本中我们提供了 过滤条和 类似 Excel 过滤方式。这无疑大大增加的 Spread 和 Excel 的兼容性,提高用户体验。

表格控件 Spread for ASP.NET 7 可以实现数据过滤, 基本步骤为创建过滤,分配过滤到指定列。同时,您可以定制过滤行和非过滤行背景色。让我们先来看下各种过滤的效果:

基本过滤:

image 

过滤条过滤:

image (1)

Excel 样式过滤:

image (2)

您可以定制过滤的许多特性,例如符合过滤条件行的样式,下面我们就来详细叙述如何实现过滤:

1.设置基本过滤,您可以定制过滤来增强用户体验。使用表单行过滤。您可以在特定列中进行过滤,从而只显示符合条件的行,同时您还可以定制这些行的外观。 您可以使用基本的过来功能,同时您也可以轻松实现自定义过滤。

1:      //设置第六列可以过滤
2:       FarPoint.Web.Spread.HideRowFilter hideRowFilter = new FarPoint.Web.Spread.HideRowFilter(FpSpread1.ActiveSheetView);
3:       hideRowFilter.ShowFilterIndicator = true; //显示 Spread 过滤按钮
4:       hideRowFilter.AddColumn(6);
5:       FpSpread1.ActiveSheetView.RowFilter = hideRowFilter; //应用过滤

 

2.设置过滤条过滤,此过滤方式是 Spread for ASP.NET 7 中新增功能,实现过滤条过滤我们需要结合 FilterBarCellType 来设置过滤条的数据类型。当过滤模式被设置为 FilterBar 时,每一列的列头下方都会生成过滤器。

您可以当前列属性设置过滤条件。在点击过滤按钮后,Spread 自动过滤符合条件的行。

1:  
 2:     //设置 Spread 过滤模式
 3:     sheet.AutoFilterMode = FarPoint.Web.Spread.AutoFilterMode.FilterBar;
 4:  
 5:     //设置第四列的过滤类型为数值型
 6:     FarPoint.Web.Spread.FilterBarCellType ct = new FarPoint.Web.Spread.FilterBarCellType();
 7:     ct.MenuType = FarPoint.Web.Spread.FilterMenuType.Number;
 8:     sheet.FilterBar.Cells[3].CellType = ct;
 9:  
 10:     //设置第五、六列的过滤类型为日期型
 11:     FarPoint.Web.Spread.FilterBarCellType ct1 = new FarPoint.Web.Spread.FilterBarCellType();
 12:     ct1.FormatString = "MM/dd/yyyy";
 13:     ct1.MenuType = FarPoint.Web.Spread.FilterMenuType.Date;
 14:  
 15:     sheet.FilterBar.Cells[4].CellType = ct1;
 16:     sheet.FilterBar.Cells[4].BackColor = System.Drawing.Color.Yellow;
 17:  
 18:     sheet.FilterBar.Cells[5].CellType = ct1;
 19:     sheet.FilterBar.Cells[5].BackColor = System.Drawing.Color.Tomato;

 

3.Excel 样式过滤,此过滤方式是 Spread for ASP.NET 7 中新增功能。需要结合 FilterColumnDefinition 实现。只显示符合过滤条件的行,自动隐藏其他行。执行过滤之后,您可以复制、查找、编辑、格式化、生成图表,并且您可以在无需重新排列或移动的条件下打印过滤数据子集。

您也可以在多列基础上进行排序。过滤功能是可以叠加使用的,这就意味着每个过滤条件都是在当前过滤结果的基础上进行过滤的。

1:      sheet.AutoFilterMode = FarPoint.Web.Spread.AutoFilterMode.Enhanced;
 2:       FarPoint.Web.Spread.IRowFilter rowFilter = new FarPoint.Web.Spread.HideRowFilter(sheet);
 3:  
 4:       FarPoint.Web.Spread.FilterColumnDefinition fd0 = new FarPoint.Web.Spread.FilterColumnDefinition(2, FarPoint.Web.Spread.FilterListBehavior.Default);
 5:       FarPoint.Web.Spread.FilterColumnDefinition fd3 = new FarPoint.Web.Spread.FilterColumnDefinition(3, FarPoint.Web.Spread.FilterListBehavior.Default);
 6:       FarPoint.Web.Spread.FilterColumnDefinition fd4 = new FarPoint.Web.Spread.FilterColumnDefinition(4, FarPoint.Web.Spread.FilterListBehavior.Default);
 7:       FarPoint.Web.Spread.FilterColumnDefinition fd5 = new FarPoint.Web.Spread.FilterColumnDefinition(5, FarPoint.Web.Spread.FilterListBehavior.Default);
 8:       FarPoint.Web.Spread.FilterColumnDefinition fd6 = new FarPoint.Web.Spread.FilterColumnDefinition(6, FarPoint.Web.Spread.FilterListBehavior.Default);
 9:       rowFilter.ColumnDefinitions.Add(fd0);
 10:       rowFilter.ColumnDefinitions.Add(fd3);
 11:       rowFilter.ColumnDefinitions.Add(fd4);
 12:       rowFilter.ColumnDefinitions.Add(fd5);
 13:       rowFilter.ColumnDefinitions.Add(fd6);
 14:  
 15:       sheet.RowFilter = rowFilter;

 

好了,以上即为 Spread 过滤特性。

更多新特性请参考在线演示实例:

http://www.grapecity.com.cn/LiveSamples/Spread/ASPNET/sampleexplorer/samples/Filter/Overview.aspx

同时,您也可以下载源码:

/developer/spreadstudio/demo


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网