Custom Aggregates in FlexGrid

Posted by: mrhaasguy on 14 September 2017, 2:24 am EST

  • Posted 14 September 2017, 2:24 am EST


    We have a grid that is grouped on a column, and we need to add aggregates for other columns to the summarized rows. Namely, we have a set of number columns that we need to add. However, these number columns are represented as strings, and we pass these strings into a function that formats the numbers in the desired way (for example with the specified number of decimals, with the correct currency symbol, with the correct decimal separator according to the culture, etc)

    Since these columns are not actually number types in Javascript, we cannot use the built-in aggregate functionality for them. Is there any way to provide a method that does a custom aggregates, so that we can provide a function that adds up string representation of numbers?

    Thank you!

  • Posted 14 September 2017, 2:24 am EST


    Aggregates are available by default in FlexGrid. You just need to set the ‘aggregate’ property on the columns you wish to calculate for. Also, it is not required for you to format the numbers in a different function. To display a particular number of decimal places and currency symbol, you simply need to set the ‘format’ property to ‘c2’ (to display the currency symbol and 2 decimal places).

    [js]{ header: ‘Revenue’, binding: ‘amount’, format: ‘c2’, aggregate: “Sum” }[/js]

    Now to display the correct currency symbol and the decimal separator, you only need to include the culture specific js file. The culture js files are shipped with the Wijmo package. You can find them at the following location in the downloaded package : \C1Wijmo-Eval_5.20152.84\Dist\controls\cultures

    You can add the required culture’s js file to your project and add a reference to it as below (for German culture) :


    Hope it clarifies things for you.

  • Posted 14 September 2017, 2:24 am EST

    Hello ABDIASM,

    aggregate: “Sum” is not working in my project but aggregate: “Cnt” or “Max” or “Min” or “Rng” are working correctly. The only problem with “Sum” and “Avg” names. Please suggest the required namespaces or whatever needed in order to work with aggregate property.

    Thank you

  • Posted 14 September 2017, 2:24 am EST


    I have attached a demo sample for your reference with your requirements implemented. When you run it, select Country from the Group By drop down below FlexGrid and observe that the Aggregated Sum is displayed in the group headers for the Revenue column.

    Let me know if you face any issues. 2015/09/

  • Posted 14 September 2017, 2:24 am EST

    Can we create new custom aggregate function with custom calculation ?

    Thank you

  • Posted 14 September 2017, 2:24 am EST

    Hi, We are extremely sorry for the delayed response You can not define custom aggregate function in FlexGrid that can directly use as default aggregate. However, by defining function and using formatItem, you can use custom aggregate function in FlexGrid.

    For reference, please see the fiddle that implements the same.

    Thanks, Manish Kumar Gupta

  • Posted 13 February 2022, 5:22 pm EST

    We have a similar requirement.

    Specifically, in addition to providing one of the pre-implemented functions like ‘Avg’ and ‘First’, we would like to be able to configure the FlexGrid to use a reducer function so that we can determine the group value using whatever means we see fit, without requiring formatItem changes.

    Are there any open enhancement requests so that this functionality can be implemented by Wijmo? I saw reference to tracking id 236552 in General Discussion | GrapeCity Forums, but am unable to see the detail of this enhancement request.

  • Posted 14 February 2022, 10:53 pm EST

    To achieve the required functionality, you may override the getAggregate method of wijmo core module and add support for your custom aggregates. Please refer to the following sample which demonstrates the same:

  • Posted 28 February 2022, 11:32 am EST

    Thanks Sharad,

    It doesn’t really work for us in our context (Angular, compiling to ES6) - we can’t replace the getAggregate method in the Wijmo core module like your example does.

    Other techniques such as generating the value in formatItem seem to be limited work-arounds at best. For example, if I copy the grid content to the clipboard and paste to excel, any value generated in formatItem is not brought across (I tried this with Wijmo’s own examples, such as Custom Aggregates | Grid | Angular Wijmo Demos).

    It would be nice if Wijmo’s getAggregate function would accept either one of the predefined aggregate types, OR, allow a reducer function to be supplied (in which case that function would be used). This was how I was going to attempt the integration - but, as per my comments above, that isn’t going to work for us.

    Are there any such enhancements planned? On the surface, it seems pretty straightforward and would solve a bunch of problems for us.

  • Posted 1 March 2022, 11:35 pm EST


    It seems there is some issue in implementing the workaround in Angular. We have asked the Dev team to look into the issue. We have also escalated the enhancements request to the Dev team with an internal tracking ID WJM-22591, will provide you a response as soon as we get any updates on this.


  • Posted 2 March 2022, 2:34 pm EST

    I’ve managed to more-or-less achieve your suggestion, indirectly at least.

    Whilst the exported function in the ES6 module is not modifiable, I do have access to the CollectionViewGroup instances, and I am able to replace the getAggregate function on these instances which achieves the desired outcome.

      .filter(r => r instanceof GroupRow)
      .map(r => r as GroupRow)
      .forEach(group => group.dataItem.getAggregate = /* the replacement function here */ );

    Still, this is not ideal, and it would be far nicer to supply the reducer function as described, but in the meantime the above might help others in a similar situation.

  • Posted 3 March 2022, 10:48 pm EST


    We are glad that you were able to find a solution to the problem on your own. We have already escalated an enhancement request for this and will provide you with a response as soon as we get any updates on this.

    Thank you for sharing your approach with us.


Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels