在网格的每个过滤器旁边显示行数

编程入门 行业动态 更新时间:2024-10-23 15:17:12
本文介绍了在网格的每个过滤器旁边显示行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用AG网格企业来显示我的数据。我为每列都有过滤器。我想显示过滤器下拉列表中每个过滤器元素的数量。请帮忙。就像过滤器显示国家/地区列中只有我们和加拿大一样,我想在这些过滤器元素旁边的括号内显示我们和加拿大的频率

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

推荐答案

更新:添加了工作样本

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 定义只是为了清楚起见。

rowData definition just for clarity.

有关更多信息,请检查文档和示例,以及演示和来源。

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

更新:添加了热门数据样本

Update: added hot data sample

一旦我们需要数据-与排序或过滤相关,我们可以使用API​​方法: forEachNodeAfterFilter , forEachNodeAfterFilterAndSort , getDisplayedRowCount 。

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})`; }

plnkr.co/edit/bCI0SJ (检查国家/地区和运动过滤器)

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

样本<$ c每次您选择\取消选择国家/地区的任何内容后,运动过滤器中的$ c> plnkr 计数将重新计算/ code>过滤器

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

更新:通过 cellRenderer

Update: hot changes handling via cellRenderer

所以 ag-grid 团队注意到了这个问题,他们在 backlock -在此之前-无法像我们尝试的那样处理您的要求。 在这里,您可以找到问题(AG-2078)

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)

更多推荐

在网格的每个过滤器旁边显示行数

本文发布于:2023-11-23 01:34:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   过滤器   行数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!