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
343
Summarydefinition Count empty| not empty
posted

Hello all,

i would like to set up to SummaryDefinition in the control xamdataGrid as follow :

 1 -  the First one 'Count' the total of records where the  value of the cell "CODE" is not empty ;

 2 - The second one 'Count' the total of records where the value of  cell "CODE" is empty ;

i am asking if there is any example related to my task or something similar .

Thanks

jay

  • 6365
    Verified Answer
    Offline posted

    Hello gerryjj,

    Thank you for the SummaryDefinitions' descriptions you have provided.

    In order to apply a summary definition that calculates the count of empty and not empty cell values for a specific field based on all the records, I can suggest you create a couple of custom summary calculators that inherit the SummaryCalculator abstract class and implement the necessary methods.
    This way by registering them prior to the InitializeComponent method in the window's constructor, you will be able to reference the custom calculators in your application by using their implemented Name property.

    XAML:

    <igDP:FieldLayout.SummaryDefinitions>
        <igDP:SummaryDefinition Calculator="EmptyCount" SourceFieldName="Code" />
        <igDP:SummaryDefinition Calculator="NotEmptyCount" SourceFieldName="Code" />
    </igDP:FieldLayout.SummaryDefinitions>

    Code-behind:

    // Implementation is analogical for the NotEmptySummaryCalculator

    public class EmptySummaryCalculator : SummaryCalculator
    {
        private int emptyRecordValuesCount;
        public EmptySummaryCalculator() : base() { }

        public override void BeginCalculation(SummaryResult summaryResult)
        {        emptyRecordValuesCount = 0;    }

        public override bool CanProcessDataType(Type dataType)
        {        return dataType == typeof(string);    }

        public override void Aggregate(object dataValue, Infragistics.Windows.DataPresenter.SummaryResult summaryResult, Record record)
        {
            if (dataValue != null &&
                (record as DataRecord) != null &&
                dataValue.ToString() == string.Empty)
            {            emptyRecordValuesCount++;        }
        }

        public override object EndCalculation(Infragistics.Windows.DataPresenter.SummaryResult summaryResult)
        {        return emptyRecordValuesCount;    }

        public override string Name { get { return "EmptyCount"; } }
        public override string Description { get { return "Calculation of empty values"; } }
    }

    I have attached a sample application that demonstrates the approach from above.

    For more detailed information on creating custom summary calculators, I can suggest you look at the following topic.

    If you have any questions, please let me know.

    XamDataGrid_sample.zip