// specify the columns
const columnDefs = [
{
field: "model.value",
headerName: "Model"
},
{
field: "make.value",
headerName: "Make"
},
{
field: "price.value",
headerName: "Price"
},
];
const autoGroupColumnDef = {
}
// let the grid know which columns and what data to use
const gridOptions = {
columnDefs: columnDefs,
defaultColDef: {
flex: 1,
minWidth: 110,
editable: true,
resizable: true,
},
onCellValueChanged: onCellValueChanged,
};
function onCellValueChanged(event) {
console.clear()
console.log('data after changes is: ', event.data);
var cols = event.column.colDef.headerName.toLowerCase()
console.log('data column name--', event.column.colDef.headerName.toLowerCase());
console.log('data after changes is: ', event.data[cols]);
}
// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function() {
// lookup the container we want the Grid to use
const eGridDiv = document.querySelector('#myGrid');
// create the grid passing in the div to use together with the columns & data we want to use
new agGrid.Grid(eGridDiv, gridOptions);
let jsonObj = `[
{ "make":{"value": "Toyota", "cell_id":"22,331,1"}, "model": {"value": "Hilux", "cell_id":"22,331,2"}, "price": {"value": 80899, "cell_id":"22,331,3"} },
{ "make":{"value": "MBW", "cell_id":"22,332,1"}, "model": {"value": "I8", "cell_id":"22,332,2"}, "price": {"value": 300899, "cell_id":"22,332,3"} }
]`;
gridOptions.api.setRowData(JSON.parse(jsonObj));
gridOptions.api.sizeColumnsToFit();
});
<html>
<head>
<script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.noStyle.js"></script>
<link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-grid.css">
<link rel="stylesheet" href="https://unpkg.com/ag-grid-community/dist/styles/ag-theme-alpine.css">
</head>
<body>
<div id="myGrid" style="height: 80vh;width:100%" class="ag-theme-alpine"></div>
</body>
</html>