<ejs-grid id="GridUS_doc" enableHover="false" allowPaging="true" allowResizing="true" allowSorting="true" allowSelection="true" allowGrouping="true" cellSelected="cellSelected" dataSource="ViewBag.dataSource" >
<e-grid-groupsettings columns="@(new string[] { "EmployeeID"})" showGroupedColumn="false" showDropArea="false"></e-grid-groupsettings>
<e-grid-pageSettings pageCount="2" pageSize="5"> </e-grid-pageSettings>
<e-grid-selectionSettings mode="Cell" type="Single"></e-grid-selectionSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="ID" isPrimaryKey="true" textAlign="Right"></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID" isPrimaryKey="true" textAlign="Left"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="EmployeeID" textAlign="Left"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Left"></e-grid-column>
<e-grid-column field="ShipName" headerText="ShipName" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function cellSelected(e) {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
var field = grid.columns[e.cellIndex.cellIndex].field;
console.log("field-- "+ field);
}
</script> |
<ejs-grid id="GridUS_doc" created='created' allowPaging="true"cellSelected="cellSelected" dataSource="ViewBag.dataSource">
<e-grid-selectionSettings mode="Cell" type="Single"></e-grid-selectionSettings>
<e-grid-columns>
<e-grid-column field="ShipName" headerText="ShipName" width="150"></e-grid-column>
. . .
</e-grid-columns>
</ejs-grid>
<br />
<script>
function created(args) {
// we are binding the mousedown event inside the “created” event of Grid.
this.element.addEventListener("mousedown", function (e) {
if (e.button == 2 && e.target.classList.contains("e-rowcell")) {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]
var rowObj = grid.getRowObjectFromUID(ej.base.closest(e.target, '.e-row').getAttribute('data-uid')); // getting row information
var r_index = rowObj.index;
var c_index = parseInt(e.target.getAttribute("aria-colindex"));
grid.selectCell({ rowIndex: r_index, c_index: }, true);
}
});
}
</script> |