Display rowcount beside each filter at grid

*爱你&永不变心* 提交于 2019-12-24 20:44:59

问题


I am using AG grid enterprise to display my data. I have filters for each columns. I want to show the count of each filter element inside the filter drop-down itself. Please help. It's like if the filter shows that we have only us and Canada in the country column, I want to display the frequencies of us and canada inside parenthesis beside these filter elements


回答1:


Update: added working sample

filterParams: { cellRenderer: "countryFilterRenderer"}

countryFilterRenderer(params) {
  let count = this.rowData.filter(i=>i.country.name==params.value).length;
  return `${params.value}(${count})`;
}

rowData:[{country:{name:..., code:...}];

rowData definition just for clarity.

For more info check doc with samples, and official demo with sources.

Update: added hot data sample

Once we need to have data - related from sorting or filtering we can use API methods: forEachNodeAfterFilter, forEachNodeAfterFilterAndSort, getDisplayedRowCount.

sportFilterRenderer(params){
    let count;
    if(this.gridApi.getDisplayedRowCount() != this.rowData.length){
      count = 0;
      this.gridApi.forEachNodeAfterFilter(node=>{
        if(node.data.sport == params.value)
          count++;
      })
    }
    else{
        count = this.rowData.filter(i=>i.sport==params.value).length;
    }
    return `${params.value}(${count})`;
}

https://plnkr.co/edit/bCI0SJ (check country and sport filters)

On sample plnkr count in sport filter would be recalculated every time once you will select\deselect anything from country filter

Update: hot changes handling via cellRenderer

So ag-grid team noticed about this issues and they have it on backlock - before this - there is no way to handle your requirement in the same way as we tried. Here you can find an issue (AG-2078)



来源:https://stackoverflow.com/questions/52220382/display-rowcount-beside-each-filter-at-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!