your solution seems to work fine as long as there are fixed number of group by columns i.e., level of nesting of columns, but it might break otherwise.
Columns().each() API could be used for more generic results.
pivotCM: function(evt, ui) {
this.Columns().each(function(col){
var cm = col.colModel
if(!cm || !cm.length) //last level column.
col.title = col.title.replace('sum', '').replace('avg', '').replace('(', '').replace(')', '')
}, ui.CM);
}