<!DOCTYPE html>
<html lang="en">
<head>
    <script>var __basePath = '/';</script>
    <style media="only screen">
        html, body {
            height: 100%;
            width: 100%;
            margin: 0;
            box-sizing: border-box;
            -webkit-overflow-scrolling: touch;
        }

        html {
            position: absolute;
            top: 0;
            left: 0;
            padding: 0;
            overflow: auto;
        }

        body {
            padding: 1rem;
            overflow: auto;
        }

        button {
            margin: 10px;
        }
    </style>
            <script src="https://unpkg.com/@ag-grid-enterprise/all-modules@23.1.1/dist/ag-grid-enterprise.min.js"></script>
    </head>

<body>
    <button onclick="getSelectedRowData()">Get Selected Nodes</button>
    <div id="myGrid" class="ag-theme-alpine" style="height: 100%;"></div>

    <script src="main.js"></script>
</body>
</html>
var gridOptions = {
  columnDefs: [
    { field: 'athlete', minWidth: 150 },
    { field: 'age', maxWidth: 90 },
    { field: 'country', minWidth: 150 },
    { field: 'year', maxWidth: 90 },
    { field: 'date', minWidth: 150 },
    { field: 'sport', minWidth: 150 },
    { field: 'gold' },
    { field: 'silver' },
    { field: 'bronze' },
    { field: 'total' },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: 'multiple',
};

function getSelectedRowData() {
  let selectedNodes = gridOptions.api.getSelectedNodes();
  let selectedData = selectedNodes.map(node => node.data);
  alert(`Selected Nodes:\n${JSON.stringify(selectedData)}`);
}

// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
  var gridDiv = document.querySelector('#myGrid');
  new agGrid.Grid(gridDiv, gridOptions);

  agGrid
    .simpleHttpRequest({
      url:
        'https://raw.githubusercontent.com/ag-grid/ag-grid/master/grid-packages/ag-grid-docs/src/olympicWinnersSmall.json',
    })
    .then(function(data) {
      gridOptions.api.setRowData(data);
    });
});