Category / Section
How to get row value on onclick event using JavaScript DataGrid?
4 mins read
You can get the JavaScript DataGrid 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
Conclusion
I hope you enjoyed learning how to get row value on onclick event using JavaScript DataGrid.
You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Grid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!