AgGrid 多组计数

AgGrid multigroup count

在 AgGrid multi-group 列场景中,如何显示第一列以具有第二列的计数。?

在下面的示例中,美国在其中显示 (1109) 行,但我想显示 (7),其中的年数。 所以它应该显示 United States (7) 。如何实现这个?

似乎在组设置中定义自定义 innerRenderer 可能是这里的正确解决方案。

  1. gridOptions 内添加 autoGroupColumnDef 属性作为自动分组列使用的配置
var gridOptions = {
    autoGroupColumnDef: {
        width: 200,
        headerName: 'Group', //header name of the group
        cellRenderer: 'agGroupCellRenderer', //default cell renderer for groupings
        // provide extra params to the cellRenderer
        cellRendererParams: {
            suppressCount: true, // turn off the row count (in order to skip default stack counting)
            innerRenderer: customInnerRenderer, //our inner renderer in charge of child nodes counting
        }
    },
    //other settings
    columnDefs: columnDefs,
    animateRows: true,
    enableRangeSelection: true,
    rowData: null
};

  1. 定义将处理计数显示的 customInnerRenderer
function customInnerRenderer(params){
    //this verification is necessary, otherwise the grid will brake down
    //when last level without grouping will be reached (if exists)
    if (params.node.group) {
        var label = params.value ? params.value : '-';
        return label + ' (' + params.node.childrenAfterFilter.length  + ')';
    }
}