关于devexpress:WinForm界面开发小技巧如何将Pivot-Grid用作主筛选器项

45次阅读

共计 3380 个字符,预计需要花费 9 分钟才能阅读完成。

点击获取工具 >>

先决条件
  • 平台:Business Intelligence
  • 产品:WinForms Dashboard

本文演示如何应用 Pivot dashboard 我的项目像单选主过滤器我的项目一样运行,此办法应用以下性能:按仪表板参数进行过滤、对根底控件的拜访,条件格局设置以及用于拜访根底数据的 API 办法。

  1. 在要用于过滤的 Pivot item 中创立一组与尺寸对应的仪表盘参数,本文应用四个参数:ProductParam、CategoryParam、CountryParam 和 CityParam,它们对应于按 Periods Pivot item 的 Product Amount 行和列局部中应用的 Product、Category、Country 和 City。
  2. 解决 DashboardDesigner.DashboardItemClick 事件,来从 clicked 元素获取尺寸的值,并将其传递给仪表盘参数。

C#

`void OnDashboardItemClick(object sender, DashboardItemMouseActionEventArgs e) {
if(e.DashboardItemName == “pivotDashboardItem1” && !skipFiltering) {
dashboardDesigner1.BeginUpdateParameters();
//clear all parameters
ClearPivotFilter();
//set selected columns and rows to parameters
SetParameterValue(e.GetAxisPoint(“Column”));
SetParameterValue(e.GetAxisPoint(“Row”));
dashboardDesigner1.EndUpdateParameters();
}
}`

skipFiltering 变量批示是否按下 Expand / Collapse 按钮,在这种状况下,该变量用于跳过设置过滤器。

  1. 下面的代码段未设置或革除单击元素无法访问的尺寸值,您须要设置仅与所选相交点对应的参数值,并在设置新的值之前革除仪表盘参数中的先前值。

创立以下用于革除参数值的办法:

C#

`void ClearPivotFilter() {
PivotDashboardItem pivotItem = dashboardDesigner1.Dashboard.Items[“pivotDashboardItem1”] as PivotDashboardItem;
ClearParameters(pivotItem.Columns);
ClearParameters(pivotItem.Rows);
}

void ClearParameters(DimensionCollection dimensions) {
foreach(var dimension in dimensions)
dashboardDesigner1.Parameters[GetParameterDataMember(dimension.DataMember)].SelectedValue = null;
}`

  1. 当最终用户单击行或列中的 Expand / Collapse 按钮时,Dashboard Designer 将引发 DashboardDesigner.DashboardItemClick 事件,解决 DashboardDesigner.DashboardItemControlCreated 事件来在这种状况下跳过设置过滤器。

C#

`bool skipFiltering = false;
private void dashboardDesigner1_DashboardItemControlCreated(object sender, DevExpress.DashboardWin.DashboardItemControlEventArgs e) {
if(e.DashboardItemName == “pivotDashboardItem1”) {
e.PivotGridControl.MouseDown += PivotGridControl_MouseDown;
}
}

private void PivotGridControl_MouseDown(object sender, MouseEventArgs e) {
PivotGridControl pivot = sender as PivotGridControl;
PivotGridHitInfo hi = pivot.CalcHitInfo(e.Location);
skipFiltering = (hi.ValueInfo != null && hi.ValueInfo.ValueHitTest == PivotGridValueHitTest.ExpandButton);
}`

  1. 要通过与 Pivot Item 相干的仪表盘参数筛选其仪表盘项时,请向这些项增加所有必须的尺寸。如果不想向最终用户显示尺寸,请将尺寸搁置到 ”Hidden Dimensions” 局部。

而后将以下过滤器表达式增加到仪表盘我的项目:

Code

([Dimension1] = ?Dimension1Param Or ?Dimension1Param Is Null) And
([Dimension2] = ?Dimension2Param Or ?Dimension2Param Is Null) And

([DimensionN] = ?DimensionNParam Or ?DimensionNParam Is Null)

本示例应用以下表达式:

Code

([Product] = ?ProductParam Or ?ProductParam Is Null)
And ([Category] = ?CategoryParam Or ?CategoryParam Is Null)
And ([Country] = ?CountryParam Or ?CountryParam Is Null)
And ([City] = ?CityParam Or ?CityParam Is Null)

下面的步骤足以实现起码的过滤性能,进一步的步骤将改善 UI 操作。

  1. Optional. To 突出显示在 Pivot Grid 中抉择的单元格,请应用以下表达式增加格局规定:

(?CityParam Is Not Null Or ?CountryParam Is Not Null Or ?ProductParam Is Not Null Or ?CategoryParam Is Not Null) And ([Product] = ?ProductParam Or ?ProductParam Is Null) And ([Category] = ?CategoryParam Or ?CategoryParam Is Null) And ([Country] = ?CountryParam Or ?CountryParam Is Null) And ([City] = ?CityParam Or ?CityParam Is Null)

  1. Optional. 解决 DashboardDesigner.CustomizeDashboardItemCaption 事件,将 Clear Master Filter 按钮增加到该项目标题目:

C#

`void OnCustomizeDashboardItemCaption(object sender, CustomizeDashboardItemCaptionEventArgs e) {
if(e.DashboardItemName == “pivotDashboardItem1”) {
DashboardToolbarItem showDataItem = new DashboardToolbarItem(“Clear Master Filter”,
new Action((args) => {
dashboardDesigner1.BeginUpdateParameters();
ClearPivotFilter();
dashboardDesigner1.EndUpdateParameters();
}));
showDataItem.Enabled = IsAnyFilterSet();
showDataItem.SvgImage = svgImageCollection1[0];
e.Items.Insert(0, showDataItem);
}
}`

正文完
 0