Access to rowIndex in javascript from context menu in AG Grid

hi,
I can’t access in javascript to the rowIndex of the row
when right click context menu in AG GRID.

Any idea ?

____ app.py _________________________

import dash_ag_grid as dag
from dash import Dash, html

app = Dash(__name__)

app.layout = html.Div(
    [
        dag.AgGrid(id="myGrid",
        rowData = [{"id": 0, "column": "cell0"},
                   {"id": 1, "column": "cell1"},
                   {"id": 2, "column": "cell2"}],
        columnDefs=[{"field": 'id'},
                    {"field": 'column'}],
        dashGridOptions={
            "allowContextMenuWithControlKey": True,
            "getContextMenuItems" :{"function": "getContextMenu(params)"}},
        enableEnterpriseModules=True,
        licenseKey = '')
    ]
)

if __name__ == "__main__":
    app.run(debug=True)


______ dashAgGridFunctions.js_________________________
var dagfuncs = window.dashAgGridFunctions = window.dashAgGridFunctions || {};

dagfuncs.getContextMenu = (params) => {
  var result = [{
      name: 'right click',
      action: () => {
        console.log(params.value)                   // ok
        console.log(params.column.getId())   // ok
        console.log(params.rowIndex)          // undefined !?
      }
    }
  ];
  return result;
};

Hi @Sta

Try using params.node.rowIndex

It’s also recommended to set the row id’s when you define the grid. see more details here: Row IDs | Dash for Python Documentation | Plotly

1 Like

Thanks Ann MArie

1 Like