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
585
Create RowSummary for custom list of rows
posted

I have a grid with a few columns that have SummarySettings attached. In addition to showing the row summaries as a footer for the entire list or the current groupby's list, I want to make it so if you select a bunch of rows, it calculates the summaries for the selection. (Excel does something similar in its status bar if you select some cells.)

However, most of the classes like SummaryValue as well as methods like ICustomSummaryCalculator.BeginCustomSummary seem to rely on a RowsCollection, and it is apparently not possible to create a custom RowsCollection instance. I really just want to pass a subset of rows (currently an IEnumerable<UltraGridRow>) and have SummaryValue perform aggregations on that.

Is there a trick I'm missing?

Parents
  • 1980
    Offline posted

    Hello Sören, 
              
    The ICustomSummaryCalculator interface has three methods to be implemented.

    BeginCustomSummary begins the summary for the SummarySettings object passed in. The implementation of this method should reset any state variables used for calculating the summary.


    EndCustomSummary gets called when every row has been processed, so here is where the calculated summary value will be returned.

    AggregateCustomSummary -  here is where the actual calculations are done and each row that gets passed in is being processed.

    Attached is a sample project where I have created a custom summary that sums the values of the cells in the ‘Price’ column of the grid’s selected rows only. In BeginCustomSummary I set the total to zero, in the AggregateCustomSummary method I check if the row is selected and add it to the total sum and at the end in EndCustomSummary method I return the total sum.


    As there is no way for the grid to know that the summary is based on selection and it does not automatically recalculate the summaries when the selection changes, we have to handle the AfterSelectChange event and tell it when the summaries need to be recalculated.

    Please let me know if you need further assistance regarding this matter.

    SampleGrid.zip
Reply Children