|
<ejs-grid id="Grid" dataSource="@ViewBag.Data">
<e-grid-columns>
.
.
<e-grid-column headerText="Details" template="#template" width="300"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script id="template" type="text/x-template">
<button class="custom-button" onclick="buttonClick(event)">Send row data to server</button>
</script>
<script>
function buttonClick(args) {
// Grid instance
var gridObj = document.getElementById('Grid').ej2_instances[0];
// Target button’s closest row cell element is retrieved
var targetRowCell = args.target.closest('.e-rowcell');
// Target row details
var targetRowDetails = gridObj.getRowInfo(targetRowCell);
// Ajax request is sent with the target row details
var ajax = new ej.base.Ajax({
url: 'Home/GetCurrentRowData',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify([targetRowDetails.rowData]),
successHandler: function (data) {
console.log('Returned data: ' + JSON.parse(data).result);
}
});
ajax.send();
}
</script> |
|
// ‘OrderDetails’ class contains definition for all the data that will be received from the client. So this class is used here to access the data
public IActionResult GetCurrentRowData([FromBody]List<OrdersDetails> data)
{
return Json(new { result = data });
} |