(DevExpress2011控件教程)PivotGrid 自定义矩阵控件 范例1

1.       数据绑定

1.1   SqlDataSource 设置 (详见以前数据绑定)

1.2   点击ASPxPivotGrid ,右键,在ASPxPivotGrid 任务中-> Choose Data Source 选择SqlDataSource1 .

1.3   点击 Fields ,弹出ASPxPivotGrid Fields Editor 窗体。选择Retrieve fields,你选择的表所有字段都会列出,然后你可以增删你需要的列。

Behaviour ->Area 中,选择好你的行和列以及统计的数值

ColumnArea:

RowArea :行

DataArea :数据值(必须为数字类型)

1.4   运行可见效果


 

2.       外观与设计

2.1   头的可见性

ASPxPivotGrid控件提供4个属性去控制field头或者头区域。

ASPxPivotGrid1.OptionsView.ShowRowHeaders=True;

 

2.2   统计属性设置基于 OptionsView.TatalsLocation

RowTotalsLocation 值有Far,Near

2.3   水平滚动条

OptionView ->ShowHorizontalScrollBar =True

2.4   AspxPivotGrid 控件能给你提供个性化的cell展示。

 protected void ASPxPivotGrid1_CustomCellStyle(object sender, DevExpress.Web.ASPxPivotGrid.PivotCustomCellStyleEventArgs e) {
           
if(e.ColumnValueType == PivotGridValueType.Total || e.RowValueType == PivotGridValueType.Total)

//设置统计的颜色
            
e.CellStyle.BackColor = Color.FromArgb(213, 227, 230);

         }

3.       统计

3.1   单独统计

AspxPivotGrid自动为每行或者每列进行统计。同样统计可以自动计算每组的值

OptionsView 属性中有

ShowRowTotals ShowRowGrandTotals

ShowColumnTotalsShowColumnGrandTotals

3.2    Top

对于列值或者行值,你可以特别的设计去展示多少条记录和计算统计值

数据->TopValueCount = Number

 

3.3   统计排序

Height :排序值

Category :统计字段

PivotGridField selField = pivotGrid.Fields["Height"];

            if (selField == null) return;

            selField.CellStyle.Font.Bold = true;

            pivotGrid.Fields["Category"].SortBySummaryInfo.FieldName = selField.FieldName;

            pivotGrid.Fields["Category "].SortBySummaryInfo.SummaryType = selField.SummaryType;

 

 

3.4    

4.       数据导出

ASPxPivotGridExporter1.ExportPdfToResponse(fileName, saveAs);

ASPxPivotGridExporter1.ExportXlsToResponse(fileName, saveAs)

ASPxPivotGridExporter1.ExportMhtToResponse(fileName, saveAs)

ASPxPivotGridExporter1.ExportRtfToResponse(fileName, saveAs)

ASPxPivotGridExporter1.ExportTextToResponse(fileName, saveAs);

 

5.       自定义过滤字段

  if (!IsPostBack && !IsCallback) {

                PivotGridField field = ASPxPivotGrid1.Fields["fieldgroupDesc "];

                // Locks the control to prevent excessive updates when multiple properties are modified.

                ASPxPivotGrid1.BeginUpdate();

                try {

                   // Clears the filter value collection and add two items to it.

                    field.FilterValues.Clear();

                    field.FilterValues.Add("A");

                    field.FilterValues.Add("B");

                    // Specifies that the control should only display the records

                    // which contain the specified values in the Country field.

                    field.FilterValues.FilterType = DevExpress.XtraPivotGrid.PivotFilterType.Included;

                }

                finally {

                    // Unlocks the control.

                    ASPxPivotGrid1.EndUpdate();

                }

            }

原文地址:https://www.cnblogs.com/meetweb/p/2227067.html