Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
265
How to use custom calculator with SummaryDefinition
posted

Hello ,

I used SummaryDefinitions with xamdatagrid and had a problem about it.Grid has 4 columns and the third columns is calculated with division second column to first.(it already exists as calculated on entity)

My  field definitions like this :

     

 <igDP:Field Name="Column0" Label="Column0" SummaryStringFormats="{}sum: Total"></igDP:Field>
   <igDP:Field Name="Column1" Label="Column1" SummaryStringFormats="{}sum: {0:N0}">
     <igDP:Field.Settings>
        <igDP:FieldSettings EditorStyle="{StaticResource NumericEditorStyle}"></igDP:FieldSettings>
          </igDP:Field.Settings>
   </igDP:Field>
   <igDP:Field Name="Column2" Label="Column2" SummaryStringFormats="{}sum: {0:N0}">
     <igDP:Field.Settings>
       <igDP:FieldSettings EditorStyle="{StaticResource NumericEditorStyle}"></igDP:FieldSettings>
         </igDP:Field.Settings>
    </igDP:Field>
    <igDP:Field Name="Column3" Label="Column3" SummaryStringFormats="{}sum: {0:P0}">
      <igDP:Field.Settings>
        <igDP:FieldSettings>
           <igDP:FieldSettings.EditorStyle>
               <Style TargetType="{x:Type igEditors:XamNumericEditor}">
                  <Setter Property="Format" Value="P0"></Setter>
                </Style>
            </igDP:FieldSettings.EditorStyle> 
         </igDP:FieldSettings>
    </igDP:Field.Settings>
 </igDP:Field>

 

My definitions like this :

<igDP:SummaryDefinition Key="Column1" SourceFieldName="Column1" Calculator="Sum"/>
<igDP:SummaryDefinition Key="Column2" SourceFieldName="Column2" Calculator="Sum"/>
<igDP:SummaryDefinition Key="Column3" SourceFieldName="Column3" Calculator="Sum"/>
 

for example :

       column1  column2 column3

         100          10          %10

          70           10          %7

Total  170          20          %17

 

Total Column3 is %17 ,sum works fine but i wanted to calculate it on summary by 20/170 = %11

 

To do this i created custom class like this :

  

public class CustomSummaryCalculator : SummaryCalculator    

 {

       public CustomSummaryCalculator()  : base()  {  }

        decimal column1, column2;

        public override void BeginCalculation(SummaryResult summaryResult)     

       {     

           column1 = 0;            

           column2 = 0;        

        }

        public override bool CanProcessDataType(Type dataType)     

    {       

      return dataType == typeof(Decimal);    

     }

        public override void Aggregate(object dataValue, Infragistics.Windows.DataPresenter.SummaryResult summaryResult, Record record)   

      {          

        if (dataValue != null && (record as DataRecord) != null)           

       {             

              var dataItem = (record as DataRecord).DataItem as MyContract;

                if (dataItem != null)           

          {              

             column2 += dataItem.column2;                     column1 += dataItem.column1;        

            }           

    }        

 }        

 public override object EndCalculation(Infragistics.Windows.DataPresenter.SummaryResult summaryResult)        

 {       

      return column2 != 0 ? column1 / column2 : 0;        

 }

   public override string Name         {             get             {                 return "CustomSum";             }         }

   public override string Description         {             get             {                 return "Calculation of Rate";             }         }   

  }

 

and then updated summarydefiniton for this column as :

<igDP:SummaryDefinition Key="Column3" SourceFieldName="Column3" Calculator="CustomSummaryCalculator"/>

at last register it on form constructor  :

SummaryCalculator.Register(CustomSummaryCalculator);
But it doesn't work,what is wrong about it?

 

 

 

 

 

 

Parents
  • 138253
    Offline posted

    Hello,

     

    Thank you for your post. I have been looking into it I created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.

     

    Looking forward for your reply.

    XamDataGridCustomSummaryCalculator.zip
Reply Children