For example, if you have a group defined as follows: this. Also note that getGroupRowAggįor groups, when aggregating, the grid stores the results in the colId of the column. If you cannot achieve what you want as it will make your code more complex. Using colDef.aggFunc is the preferred way of doing aggregations, only use getGroupRowAgg The following example demonstrates this approach in action: If you are unaware of the tree-like nature, your custom aggregation functions may behave differently to how you expect.įor example, with the simple mean average function below: const simpleAvg = (params ) => ] Since data rows are modelled as a tree, custom aggregation functions are applied using a depth-first recursive approach. In row grouping situations, there are some important nuances to consider when defining custom aggregation functions. This is to calculate the grand total aggregation for the top level. When the grid is empty, the aggregations are still called once with an empty set. Total footers display the result of the aggregation for top level, for example displaying a grand total even if no row grouping is active. The grand total aggregation is normally not seen, unless the grid is configured with Grouping Total Footers. For example if you have 10 rows in the grid, the grid will still call the aggregation with 10 values to get a grand total aggregation. Note that custom aggregations will get called for the top level rows to calculate a 'Grand Total', not just for row groups. Note that we also set 'xyz' in the grid options as otherwise the grid would complain 'Function not found' as it tries to use the function before it is set via the API. 'xyz' on Bronze: The 'xyz' function is another function with much use, however it demonstrates you can return anythin from an aggregation function - as long as your aggregation function can handle the result (if you have groups inside groups) and as long as your cell renderer can render the result (if using cellRenderer). The '123' function, like 'sum', is set using a gridOptions property. Having a function return the same thing isn't very useful, however for the example it demonstrates easily where in the grid the function was used. Because it is registered as an aggregation function, it can be reference by name in the column definitions. '123' on Silver: The '123' function ignores the inputs and always returns the value 123. The sum function is set using a gridOptions property. Maybe you want to provide a sum function that uses for example the math.js library. The new sum function doesn't do anything different to the built in sum function, however it serves as a demonstration on how you can override. Sum on Gold: The gold column gets a custom sum aggregated function. Rounded Average on Age Column: This is the same as Average on Age Column but forcing the values to display a maximum of two decimal numbers. The average function is also set by placing the function directly as the colDef.aggFunc. The grid also provides an average function that works in the same way, so there is no value in providing your own average function like this, it is done in this example for demonstration purposes. The average function also needs to know if it is working with leaf nodes or group nodes, as if it's group nodes then the average is weighted. The min/max function is then set by placing the function directly as the colDef.aggFunc.Īverage on Age Column: The age columns is aggregated a second time with a custom average function. This is because the result of the aggregation has two values based on one input value. If the value is a number, it's a row data item, otherwise it's a group. The function knows whether it is working with leaf nodes (original row data items) or aggregated nodes (ie groups) by checking the type of the value. Min/Max on Age Column: The function creates an aggregation over age giving a min and a max age. The following can be noted from the example: The next example shows many custom aggregation functions configured in a variety of ways and demonstrating different things aggregation functions can do. If gridApi.onFilterChanged() is not called, the grid will still show the data relevant to the filters before they were updated through the API. Numbers that will be displayed in the cell (see the Rounded Average on Age Column in the example below). After filters have been changed via their API, you must ensure the method gridApi.onFilterChanged() is called to tell the grid to filter the rows again. Reason, if your aggregations rely on decimal values, it's better to add logic to enforce the amount of decimal
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |