翻譯|行業資訊|編輯:龔雪|2023-02-20 10:45:56.620|閱讀 169 次
概述:本文將介紹DevExpress WPF的Pivot Grid組件在近幾個更新周期中增強的功能,歡迎下載相關組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
界面控件DevExpress WPF的Pivot Grid組件是一個類似excel的數據透視表,用于多維數據分析和跨選項卡報表生成。它擁有眾多的布局自定義選項,允許開發者完全控制其UI且以用戶為中心的功能使其易于部署。
PS:DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業需求的高性能業務應用程序。通過DevExpress WPF能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。
在本文中,將總結在DevExpress過去發布的幾個周期中引入的與Pivot Grid相關的增強功能。
DevExpress技術交流群7:674691612 歡迎一起進群討論
官方技術團隊首要目標是交付單一/統一的綁定機制,并簡化整個Pivot Grid設置。
Pivot Grid字段在以下模式下使用新的統一綁定機制:
更新的API是建立在迄今為止最快的引擎上的(稱之為優化計算引擎),因此統一的API允許開發者將Pivot Grid綁定到服務器模式/OLAP數據源或內存中數據源(新內存中引擎比舊的Legacy和LegacyOptimized引擎快得多)。
介紹完這些之后,現在一起看看每種可用的數據綁定類型……
使用DataSourceColumnBinding類將Pivot Grid字段綁定到數據源中的列或OLAP多維數據集中的度量/維度,在以前的版本中,開發者必須指定PivotGridFieldBase.FieldName屬性來將PivotGrid字段綁定到數據源中的列。
PivotGridField statusField = new PivotGridField() { FieldName = "[Measures].[Internet Revenue Status]", Area = PivotArea.DataArea, AreaIndex = 2, Caption = "Status", Name = "fieldStatus" }; PivotGridField quarterField = new PivotGridField() { FieldName = "[Date].[Fiscal].[Fiscal Quarter]", Area = PivotArea.RowArea, AreaIndex = 2, Caption = "Fiscal Quarter", Name = "pivotGridField" }; pivotGridControl.Fields.AddRange(new[] { quarterField, statusField });
開發者現在可以使用PivotGridField.DataBinding屬性,它能夠接收這種類型的實例,以及稍后將描述的其他實例。
PivotGridField statusField = new PivotGridField() { DataBinding = new DataSourceColumnBinding("[Measures].[Internet Revenue Status]"), Area = PivotArea.DataArea, AreaIndex = 2, Caption = "Status", Name = "fieldStatus" }; PivotGridField quarterField = new PivotGridField() { DataBinding = new DataSourceColumnBinding("[Date].[Fiscal].[Fiscal Quarter]"), Area = PivotArea.RowArea, AreaIndex = 2, Caption = "Fiscal Quarter", Name = "pivotGridField" }; pivotGridControl.Fields.AddRange(new[] { quarterField, statusField });
ExpressionDataBinding和OlapExpressionBinding允許將Pivot Grid字段分別綁定到計算表達式或MDX表達式(OLAP),此外ExpressionDataBinding可以用來實現以下Pivot Grid特性:
例如,以下來自字母分組示例應用程序的代碼片段將ProductName字段值分組為三個范圍:A-E, F-S和T-Z(基于產品名稱的初始字符)。
// Create fieldProductName and bind it to the ProductName column in the data source. PivotGridField fieldProductName = new PivotGridField(); fieldProductName.Area = PivotArea.RowArea; fieldProductName.Caption = "Product"; fieldProductName.DataBinding = new DataSourceColumnBinding("ProductName"); fieldProductName.Name = "fieldProductName"; pivotGridControl.Fields.Add("ProductName"); // Create fieldProductGroup, specify the expression, and bind it to the created field. PivotGridField fieldProductGroup = new PivotGridField(); fieldProductGroup.Area = PivotArea.RowArea; fieldProductGroup.Caption = "Product Group"; fieldProductGroup.AreaIndex = 0; fieldProductGroup.DataBinding = new ExpressionDataBinding( "iif(Substring([ProductName], 0, 1) < 'F', 'A-E', Substring([ProductName], 0, 1) < 'T', 'F-S', 'T-Z')"); pivotGridControl.Fields.Add(fieldProductGroup);
這里的好處是,開發者不需要像在以前的版本中那樣處理CustomGroupInterval事件:
pivotGridControl.CustomGroupInterval += (s, e) => { if(!object.Equals(e.Field, fieldProductGroup)) return; if(Convert.ToChar(e.Value.ToString()[0]) < 'F') { e.GroupValue = "A-E"; return; } if(Convert.ToChar(e.Value.ToString()[0]) > 'E' &x;&x; Convert.ToChar(e.Value.ToString()[0]) < 'T') { e.GroupValue = "F-S"; return; } if(Convert.ToChar(e.Value.ToString()[0]) > 'S') e.GroupValue = "T-Z"; }; pivotGridControl.RefreshData();
注意:如果您使用更新的綁定API,以前涉及以下事件的分組\排序\匯總方法將不再支持:
Binding API使用表達式進行自定義分組。開發者還可以計算自定義摘要,或對數據進行排序。
最新的版本中添加了更多的表達式函數來擴展支持使用場景的范圍:
新版本還添加了在Expression Editor中創建和注冊自定義聚合函數的功能,注冊的函數可以與預定義的Pivot Grid方法一起使用。
Pivot Grid現在支持OLAP ADOMD.NET NuGet包用于.NET Framework和.NET. With ADOMD.NET,開發者可以讀取多維模式(超過兩個軸),在多維數據集上發起查詢,并根據需要檢索結果。
更新的版本增強了Pivot Grid的異步模式,使其更加可用和穩定。
下面的代碼片段來自OLAP Drill Down 技術演示,為選定的Pivot Grid單元格創建了一個下鉆數據源,并以異步模式在DrillDownForm對話框中顯示結果數據源。
pivotGridControl.CellDoubleClick += async (s, e) => { try { pivotGridControl.LoadingPanelVisible = true; PivotDrillDownDataSource ds = await e.CreateDrillDownDataSourceAsync(); pivotGridControl.LoadingPanelVisible = false; using(DrillDownForm form = new DrillDownForm(ds)) form.ShowDialog(); } catch(Exception ex) { pivotGridControl.LoadingPanelVisible = false; XtraMessageBox.Show(ex.Message); } };
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網