Sunil kumar
Sunil kumar

Reputation: 337

AgGrid multigroup count

In AgGrid multi-group column scenario, how to display first column to have count number of second column.?

In a below example, United states shows (1109) rows in it, but i want to show (7), count of years in it. So it should show United States (7) .How to achieve this ?

enter image description here

Upvotes: 1

Views: 1045

Answers (1)

kamil-kubicki
kamil-kubicki

Reputation: 628

Seems like defining a custom innerRenderer inside the group settings might be right solution here.

  1. Add autoGroupColumnDef attribute inside gridOptions as configuration used by the auto group columns
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. Define customInnerRenderer that will handle the counting display
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  + ')';
    }
}

Upvotes: 4

Related Questions