Search results

Get specific row and cell index in Grid in ASP.NET Core Grid control

You can get the specific row and cell index of the grid by using rowSelected event of the grid. Here, we can get the row and cell index by using aria-rowindex(get row Index from tr element) and aria-colindex(column index from td element) attribute.

tagHelper
rowcellidx.cs
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" rowSelected="rowSelected">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType='dropdownedit'></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>
    function rowSelected(args) {
        alert("row index: " + args.row.getAttribute('aria-rowindex'));
        alert("column index: " + args.target.getAttribute('aria-colindex'));
    }
</script>
public IActionResult Index()
{
    ViewBag.DataSource = OrderDetails.GetAllRecords();
    return View();
}