Pivot - custom function for Group Count Percentage

I’m trying to add a custom function to find the group count percentage, but the data passed to the custom function is not enough to calculate the groupCount of a column with respect to other rows.

I tried to parse data on my own and try to use the parsed data in this custom function. But problem with this is that if there are multiple levels of rows, arguments don’t give me any reference to know which row and level this function is called.

Can you help/guide me with this.

Is this possible at all?

Can anyone from the support team reply if it’s feasible or not?

Such calculations for aggregated dataset can be performed in column template via onBeforeRender event. Template does not affect the real data, but you can calculate/render anything you need.

Here’s a snippet with the related treestore methods (treestore if a data storage of Pivot’s datatable, available as pivot.$$(“data”).data ):

https://webix.com/snippet/f3488292

Thanks for the reply. Will try and let you know

Hello Listopad,

I am able to calculate group count percentage now. But with the approach you suggested, it’s overriding default aggregators.

I’m having to define the existing aggregators (count, sum, max, min) again. Is there anyway I can know the aggregator in onBeforeRender before overriding the column template.

Please check my implementation here: https://webix.com/snippet/8ec47a0c.

Thanks!

The template is what will be rendered in the cell, it does not affect the real data operations nor the real data.

Depending on the available information (data attributes and column configuration), you can return the original calculations or the custom ones - that’s the main idea.

Template itself receives the following parameters:

template = function(obj, common, cellValue, colConfig, itemIndex){}

Perhaps, the most useful here the $parent, $level, $count and $source (the last is available only in stableRowId mode) attributes in each aggregated data item (obj in template).

For example

// percentage for the top level only
template:function(obj, common, cellValue, colConfig){
   return !obj.$parent ? getAggregator(...) : cellValue;
}

However, about operations: column ID includes all required information regarding the structure:

colLevel1_'_/* . . . */_'_colLevelN_'_operation_'_value

Apart from the first column, the operation can be obtained from the configuration:

var head = columns[i].header; // array of header lines
// last line contains value/operation/text
var operation = head[head.length-1].operation;