Search code examples
ag-grid

ag-grid - how to get parent node from child grid via context menu?


As an example, I have a Master\Detail grid.

Master\Detail defined as key-relation model and on getDetailRowData method parent node data exists in params

but how to get parent node data from child view?

Tried via context-menu:

On right click - getContextMenuItems got executed which has an input params

On this sample, child-grid doesn't have any row and node in context-params is null, it's ok, but anyway it should be possible to retrieve the parent details at least via grid API, isn't it ?

Then I've tried to get parent via node: enter image description here but instead of detail_173 as you can see its ROOT_NODE_ID, and here is a confusion for me.

So question is that how to get parent node data (RecordID 173 just in case) through child-view context menu or any other possible way (without storing temp value, cuz multiple children's could be opened at the same time)

Yes, I've read this part Accessing Detail Grid API, and still unclear how to get parent-node via child-grid.


Solution

  • A very reliable solution is to create your own detailCellRenderer.

    on the init method:

    this.masterNode = params.node.parent; 
    

    when creating the detail grid:

    detailGridOptions = {
        ...
        onCellClicked: params => console.log(this.masterNode.data)
    }
    

    Here is a plunker demonstrating this: https://next.plnkr.co/edit/8EIHpxQnlxsqe7EO