Articles in this section
Category / Section

How to get Data table row value on onclick event using JavaScript?

4 mins read

You can get the grid row details inside the click event by passing the target element to the “getRowInfo” method of the Grid component.

This is explained in the following sample code in which the “click” event has been bound to the Grid element and clicked row details are retrieved by using the “getRowInfo” method. The detail is displayed in the console window.

JS

var grid = new ej.grids.Grid({
  dataSource: data,
  columns: [
    { field: "OrderID", headerText: "Order ID", width: 120, textAlign: "Right" },
    { field: "CustomerName", headerText: "Customer Name", width: 150 },
    { field: "Freight", width: 120, format: "C2", textAlign: "Right" },
    { field: "ShipCountry", headerText: "Ship Country", width: 150 }
  ]
});
grid.appendTo("#Grid");
 
document.getElementById("Grid").addEventListener("click", function (args) {
  if (args.target.classList.contains("e-rowcell")) {
    var rowInfo = grid.getRowInfo(args.target);
 // Get row information
    console.log(rowInfo.rowData);
  }
});
 

 

Demo: https://stackblitz.com/edit/click-row-data?file=index.js      

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment