Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
141654 | Dec 25,2018 07:47 AM UTC | Jan 11,2019 05:03 AM UTC | ASP.NET Core - EJ 2 | 11 |
![]() |
Tags: DataGrid |
public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value)
{
var ord = value.value;
...
return Json(value.value);
}
public class CRUDModel<T> where T : class
{
public T value { get; set; }
}
|
[index.cshtml]
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })" allowPaging="true" actionBegin="onActionBegin" actionComplete="onActionComplete">
<e-data-manager json ="@ViewBag.datasource" adaptor="RemoteSaveAdaptor" updateUrl="Home/Update" insertUrl="Home/Insert" ></e-data-manager>
<e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
. . . .
</e-grid-columns>
</ejs-grid>
</div> |
[HomeController.cs]
public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value)
{
OrdersDetails.GetAllRecords().Add(value.value);
return Json(value.value);
}
|
[index.cshtml]
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })" allowPaging="true" actionBegin="onActionBegin" actionComplete="onActionComplete">
<e-data-manager json ="@ViewBag.datasource" adaptor="RemoteSaveAdaptor" updateUrl="Home/Update" insertUrl="Home/Insert" ></e-data-manager>
<e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120" isIdentity="true"></e-grid-column>
. . . .
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function onActionBegin(args){
if (args.requestType === 'save' && args.action ==='add') {
args.data['OrderID'] = Math.random(); // Add a random value to primary key field
}
} |
public class OrdersDetails
{
public static List<OrdersDetails> order = new List<OrdersDetails>();
public OrdersDetails()
{
}
public OrdersDetails(decimal OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress)
{
. . . .
public decimal? OrderID { get; set; }
public string CustomerID { get; set; }
public int? EmployeeID { get; set; }
. . .
} |
<div>
<input id="btnSpremi" type="submit" value="Spremi podatke firme" onclick="spremiFirmu()" class="btn btn-success" />
@Html.Hidden("dsFirmaRacuni")
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" allowPaging="true" actionBegin="onActionBegin">
<e-data-manager json="@ViewBag.datasource" adaptor="RemoteSaveAdaptor" updateUrl="Home/Update" insertUrl="Home/Insert"></e-data-manager>
<e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120" isIdentity="true"></e-grid-column>
. . . .
</e-grid-columns>
</ejs-grid>
</div>
<script>
function onActionBegin(args){
if (args.requestType === 'save') {
if (args.action === 'add') {
args.data['OrderID'] = getRandomInt(1, 100); // Set the Randow value for primary key field while add a new record
}
var val = JSON.stringify(args.data);
$("#dsFirmaRacuni").val(val); // Set the New record or edited records in hidden element
}
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function spremiFirmu() {
alert($("#dsFirmaRacuni").val()); // get the new records or changes of existing values while click the submit button
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.