GrailsLearner
GrailsLearner

Reputation: 525

Loop through ag-grid data and display values

I am looping through each node of ag-grid data and have to display column values.Attached is the plunkr: https://plnkr.co/edit/cFBLm7DkAZL5oWbqdyub?p=preview.

I am not able to display the ag-grid data in the console.

var gridOptions = {
defaultColDef: {
    sortable: true
},
columnDefs: columnDefs,
animateRows: true,
enableRangeSelection: true,
rowData: rowData,
checkbox : true,
onSelectionChanged : getData
};
   new agGrid.Grid(gridDiv, gridOptions);
});

function getData(){
  gridOptions.api.forEachNode( function (node) {
   console.log("node vaalues are:"+node.data);
});

Upvotes: 0

Views: 4107

Answers (1)

Michael Lynch
Michael Lynch

Reputation: 1743

There are a couple things wrong with your code.

  1. Inorder for onSelectChanged to be called you need to specify how you want row selection to work, try: rowSelection: 'single'

  2. In your plunkr (not your snippet above), your getData function is in the wrong scope. By this I mean all of your code is inside the document.addEventListener, but the getData is not. Because of this, getData doesn't know what gridOptions is.

Updated plunkr: https://next.plnkr.co/edit/cXKVZrT9siHoodVa

Upvotes: 1

Related Questions