$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: window.gridData,
allowPaging: true,
------------
columns: [
{ field: "OrderID", isIdentity: true, isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, width: 90 },
{ field: "CustomerID", headerText: "Customer ID", width: 90 },
{ field: "ShipCity", headerText: "Ship City", width: 90 },
-----------------
]
});
|
[app.component.html]
<ej-grid #grid [dataSource]="gridData" [allowScrolling]=true >
<e-columns>
<e-column field="OrderID" [isPrimaryKey]="true" [isIdentity]="true" width="75" textAlign="right"></e-column>
<e-column field="EmployeeID" headerText="Employee ID" [validationRules] = "{ required: true, number: true }" width="75" textAlign="right"></e-column>
<e-column field="CustomerID" headerText="CustomerID" width="80"textAlign="right"></e-column>
</e-columns>
</ej-grid>
|
[HomeController.cs]
public ActionResult Update(Orders value)
{
var data = order.ToList();
Orders result = data.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (result != null)
{
result.OrderID = value.OrderID;
result.CustomerID = value.CustomerID;
result.EmployeeID = value.EmployeeID;
}
return Json(value, JsonRequestBehavior.AllowGet);
}
public ActionResult Insert(Orders value)
{
int generate = order.ToList().Count();
value.OrderID = ++generate; // set the auto generated value to the OrderID column
order.Insert(0, value);
return Json(value, JsonRequestBehavior.AllowGet);
}
public ActionResult Delete(int key)
{
var data = order.ToList();
Orders result = data.Where(o => o.OrderID == key).FirstOrDefault();
order.Remove(result);
return Json(data, JsonRequestBehavior.AllowGet);
}
|