• PivotGridField 中对Unbound的列赋值(除法)--数据钻取


    上一中方法(http://www.cnblogs.com/shirley-w/p/4042391.html)只能计算分子和分母均在数据区域显示的除法,用数据钻取的方法可取到在其他区域甚至visible=“false”的列值

    .aspx中<Fields>内的代码:

     <dx:PivotGridField ID="field_corr" Area="DataArea" AreaIndex="0"  FieldName="诊断符合数" ValueFormat-FormatType="Numeric" Caption="诊断符合数"></dx:PivotGridField>
    <dx:PivotGridField ID="field_Sum" Area="DataArea" AreaIndex="1"  FieldName="诊断总数"  Caption="诊断总数"></dx:PivotGridField>
    <dx:PivotGridField ID="field_compare" Area="DataArea" AreaIndex="2"  FieldName="诊断符合率" Caption="诊断符合率"  UnboundType="Decimal"></dx:PivotGridField>

    其中诊断符合率=诊断符合数/诊断总数

    除法需要在后台绑定OnCustomCellDisplayText事件:OnCustomCellDisplayText="pivotGrid_CustomCellDisplayText"

    .cs

     protected void pivotGrid_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e)//通过数据钻取对病案率的计算
             {
                 if (object.ReferenceEquals(e.DataField, ASPxPGDiagnosticAccordanceRate.Fields["诊断符合率"]))
                 {
                     PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
                     int corrcount = 0;
                     int Sumcount = 0;
                     for (int i = 0; i < ds.RowCount; i++)
                     {
                         PivotDrillDownDataRow row = ds[i];
                         corrcount += (int)row[field_corr];
                         Sumcount += (int)row[field_Sum];
                     }
                     if (Sumcount > 0)
                     {
                         decimal perc = (decimal) corrcount/Sumcount;
                         e.DisplayText = string.Format("{0:p}", perc);
                     }
                 }
             }

    此方法不但可以将计算值显示在界面上,而且将“诊断符合数”、“诊断总数”列放在筛选区或者其他区域(甚至不可见,但存在此项)均可以算出结果

  • 相关阅读:
    Backtrader中文笔记之Position(持仓情况)
    Backtrader中文笔记之Broker(券商,经纪人)
    Backtrader中文笔记之Orders
    Backtrader中文笔记之Order Management and Execution ---几种价格限制交易的详细解释
    Backtrader中文笔记之Observers and Statistics
    Backtrader中文笔记之Analyzers Reference
    Backtrader中文笔记之Pyfolio Integration(待看)
    Backtrader中文笔记之PyFolio Overview
    curl basic
    plant template
  • 原文地址:https://www.cnblogs.com/shirley-w/p/4073187.html
Copyright © 2020-2023  润新知