简体   繁体   English

仅对 Ag-Grid 上的某些行进行分组

[英]Only group some rows on Ag-Grid

I'm looking at row grouping with Ag-Grid and have got it working in my project (grouping art works by master edition, with child elements being editions).我正在考虑使用 Ag-Grid 进行行分组,并在我的项目中使用它(按主版本对艺术作品进行分组,子元素是版本)。 The problem is that some art works are not master editions, nor editions.问题是有些艺术作品不是母版,也不是版本。 They're just their own work without being a part of a set.他们只是他们自己的作品,而不是一个系列的一部分。

Right now Ag-Grid creates a group for every single art work.现在 Ag-Grid 为每件艺术作品创建一个组。 So, those of type "normal" have a "normal" group, etc. I only want grouping behaviour on works of type "master edition".所以,那些“普通”类型的人有一个“普通”组,等等。我只想对“大师版”类型的作品进行分组行为。 Is there a proper way to do this?有没有合适的方法来做到这一点?

My current idea was to create a custom cell renderer that only renders HTML if params.node.group = true .我目前的想法是创建一个自定义单元格渲染器,如果params.node.group = true ,它只渲染 HTML。 This feels pretty hacky though so I was wondering if there was a better solution.虽然这感觉很hacky,所以我想知道是否有更好的解决方案。

From my understanding of your problem, a tree view could help you: https://www.ag-grid.com/javascript-grid-tree-data/根据我对您的问题的理解,树视图可以帮助您: https : //www.ag-grid.com/javascript-grid-tree-data/

You could accomplish that asymetric grouping, by creating a tree path dynamically, in the getDataPath callback in gridOptions.您可以通过在 gridOptions 的 getDataPath 回调中动态创建树路径来完成该非对称分组。

getDataPath: function(data) {
    return data.type === "master edition" ? ["master edition", data.name]: [data.name];
}

Plunker: https://next.plnkr.co/edit/3jdzvQ1QJmF7xJy1 Plunker: https ://next.plnkr.co/edit/3jdzvQ1QJmF7xJy1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM