@{
ViewData["Title"] = "Grid";
}
<ejs-button id="normalbtn" content="Render"></ejs-button>
<ejs-button id="normalbtn1" content="Send"></ejs-button>
<div>
<ejs-grid id="Grid" allowPaging="true">
<e-grid-columns>
…..
</e-grid-columns>
</ejs-grid>
</div>
<script>
document.getElementById("normalbtn1").addEventListener("click", function () {
debugger;
var gridObj = document.getElementById('Grid').ej2_instances[0];
var g = gridObj.dataSource;
var ajax = new ej.base.Ajax({
url: 'Home/GetCurrentRowData',
type: 'POST',
data: JSON.stringify( g )
});
ajax.send();
})
</script> |
public IActionResult GetCurrentRowData([FromBody]List<OrdersDetails1> data)
{
return Json(new { result = data });
} |
Index.cshtml
<ejs-button id="normalbtn" content="Render"></ejs-button>
<div>
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" 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>
</div>
<script>
document.getElementById("normalbtn").addEventListener("click", function () {
var grid = document.getElementById('Grid').ej2_instances[0]; // Grid instance
var ajax = new ej.base.Ajax('/Home/DataSource', 'GET');
ajax.send();
ajax.onSuccess = function (data) {
var dataSource = new ej.data.DataManager({
json: JSON.parse(data),
adaptor: new ej.data.RemoteSaveAdaptor(),
insertUrl: '/Home/Insert',
updateUrl: '/Home/Update',
removeUrl: '/Home/Remove'
});
grid.dataSource = dataSource;
};
});
</script>
|