javascriptcssag-gridag-grid-reactag-charts-react

how to show group parent as one cell (by combining first columns of children rows)


I would love to manage to see the parent cell as one united cell as i showed on the screenshot below. I couldn't find solution from themeing, customization docs. Could you please tell me what is the proper way of achieving this? Thanks enter image description here


Solution

  • Here you are

    https://plnkr.co/edit/oOtlvoTPuaIDB2Kd?preview

    This is the closest solution I can achieve

    Basically, we use rowSpan feature. In this example, we have 2 groups; country and year respectively. To get the desired result, we add a rowSpan method like that

    rowSpan: (params) => {
      // when all group columns collapsed
      if (params.node.field === 'country') {
        return 1;
      // when first level is expanded
      } else if (params.node.field === 'year') {
        return (
          params.node.parent.childrenAfterGroup.length -
          params.node.childIndex
        );
      // when second level is expanded
      } else {
        // if it is the latest group, our calculation logic changes
        if (params.node.parent.lastChild) {
          return (
            params.node.parent.childrenAfterGroup.length -
            params.node.childIndex
          );
        } else
          return (
            params.node.parent.childrenAfterGroup.length -
            1 +
            params.node.parent.parent.childrenAfterGroup.length -
            params.node.childIndex -
            params.node.parent.childIndex
          );
        }
      }
    },
    

    The idea is to count rows regarding the row child index. You need to observe the code and understand it, it's somewhat complicated.

    Result

    Result

    UPDATE

    If you want to have a background color only if the country column is expanded, we should add another condition to check it this way

    if (params.node.parent.expanded)
    

    Here's the updated plunker: https://plnkr.co/edit/oOtlvoTPuaIDB2Kd?preview