I have a (Pivot) grid with several data types in it – dates, string, and some numbers.
I have been tasked with fixing the behavior where if one drags a date field into the “Aggregates” box (lower right), it automatically assumes “Sum()”.
It can be clicked and changed to a proper aggregate function, like count() or Min/Max, but the default is sum(). As you know, this means the values in the grid appear as NaN or other weird formats.
One suggestion I saw was to add summary type=null to each column definition, which didn't seem to help.
As an alternative, I have some custom .js code that seems to fit the bill – almost. The code below will intercept the ‘drag-in’ and changes it to count() by default – yay! – but the data in the grid still says NaN, as though it ran it as sum(). This leads me to believe I probably need to refresh the grid to register the new change.
So even if I add the refresh, I can’t help wondering – is there a simpler way that I am overlooking? Am I going about this the hard way? Is there a much simpler approach or configuration to achieve the same?
Below please find my code scratchings: (Yes, I also need to add code to handle strings)
( event: pivotCM: )
function (evt, ui) {
//previous code to concat field value to column header
...
//Code to change from sum to count
ui.CM.forEach(col => {
if (col.dataType == "date" && col.summary.type == "sum") {
col.summary.format = "";
col.summary.type = "count";
}
if (col.dataType === "date") {
if (col.summary.type === "count") {
col.summary.format = "0";
} else {
col.summary.format = "mm/dd/yy hh:mm:ss";
}
}
});
}
Thanks!