简体   繁体   English

detailCellRendererParams的递归函数,Ag-Grid?

[英]Recursive function for detailCellRendererParams, Ag-Grid?

I have data which consists of multiple rows of data. 我有包含多行数据的数据。 Each row contains a 'children' array property, which may have data in the form of more rows, or may be empty. 每行包含一个“子级”数组属性,该属性可以具有更多行形式的数据,也可以为空。 On top of that, each of the rows within the 'children' array property may also contain more 'children' data or rows and so on, so it looks like this (think of each line as a row and each indented line as a child row of that row): 最重要的是,'children'数组属性内的每一行也可能包含更多的'children'数据或行,依此类推,因此看起来像这样(将每一行视为一行,将每个缩进行视为一个子级)该行的一行):

r|-------
 r1|------*
   r1a|------
   r1b|------*
      r1b1|------
   r1c|------*
      r1c1|------
      r1c2|------
 r2|------
 r3|------*
   r3a|------
   r3b|------

Each parent containing child rows (I marked them with '*') must have detailCellRendererParams defined, which is fine if I was just going to define each one manually ( as shown in Ag-Grid documentation under Nesting Master / Detail , however, it is uncertain how many parent/children rows there will be. I am looking to create a recursive function that defines the detailCellRendererParams for each parent row with children. How might I write something like this? 包含子行的每个父行(我用“ *”标记)必须定义detailCellRendererParams,如果我只是手动定义每行,这很好( 如Nesting Master / Detail下的Ag-Grid文档所示 ,但是我不确定要创建多少个父/子行,我正在寻找一个递归函数,为每个带有孩子的父行定义detailCellRendererParams。

No recursion required, just use the tree data functionality of ag-grid: 无需递归,只需使用ag-grid的树数据功能:

https://www.ag-grid.com/javascript-grid-tree-data/ https://www.ag-grid.com/javascript-grid-tree-data/

You need to enable tree functionality with: 您需要通过以下方式启用树功能:

var gridOptions = {
    treeData: true,
    ...
}

and provide the grid with the field that creates your tree-hierarchy 并向网格提供创建树层次结构的字段

gridOptions.getDataPath: function(data) {
   return data.myHierarchyField;
},

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

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