AgGrid多组计数

时间:2019-11-18 08:42:57

标签: javascript angularjs ag-grid

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

在下面的示例中,美国在其中显示(1109)行,但我想在其中显示(7)年。 因此应该显示United States (7)。如何实现?

enter image description here

1 个答案:

答案 0 :(得分:0)

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

  1. autoGroupColumnDef内添加gridOptions属性作为自动组列使用的配置
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  + ')';
    }
}
相关问题