Hi mahesh213,
Refer below code.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public JsonResult GetCustomers()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { Id = 1, Name = "John Hammond", DOB = DateTime.Now.AddYears(-10) });
customers.Add(new Customer { Id = 2, Name = "Mudassar Khan", DOB = DateTime.Now });
customers.Add(new Customer { Id = 3, Name = "Suzanne Mathews", DOB = DateTime.Now });
customers.Add(new Customer { Id = 4, Name = "Robert Schidner", DOB = DateTime.Now });
return Json(customers, JsonRequestBehavior.AllowGet);
}
public JsonResult UpdateCustomer(Customer customer)
{
return Json(customer, JsonRequestBehavior.AllowGet);
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public int Age { get; set; }
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.1.114/styles/kendo.default-v2.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/angular.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/kendo.all.min.js"></script>
<script type="text/javascript">
var app = angular.module("MyApp", ["kendo.directives"]);
app.controller("MyController", function ($scope, $window, $http) {
$scope.mainGridOptions = {
dataSource: {
type: "json",
transport: {
read: { url: "/Home/GetCustomers" },
update: { url: "/Home/UpdateCustomer" }
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, nullable: true, type: "number" },
Name: { editable: true, nullable: true, type: "string" },
DOB: { editable: true, nullable: true, type: "date" },
}
}
},
pageSize: 4,
serverPaging: false,
serverSorting: false
},
editable: "inline",
sortable: true,
pageable: true,
resizeable: true,
columns: [
{ field: "Id", title: "Id", width: "50px" },
{ field: "Name", title: "Name", width: "130px", validation: { required: true } },
{
field: "DOB",
title: "DOB",
width: "120px",
format: "{0:MM/dd/yyyy}",
editor: function (container, options) {
$('<input name="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '" />')
}
},
{ field: "Age", title: "Age", width: "100px" },
{
title: 'Action',
command: [{ name: "edit", text: "Edit", iconClass: "k-icon k-i-hyperlink-open" }]
}
],
edit: function (e) {
var dob = GetMMdyyyy(new Date(new Date(e.model.DOB).toDateString()));
e.model.DOB = dob;
var container = e.container;
container.find('td').eq(2).html(dob);
var txtAge = container.find("input[name=Age]");
$(txtAge).val(CalculateAge(dob));
}
};
})
function GetMMdyyyy(date) {
var date = new Date(date);
var dd = date.getDate();
var mm = date.getMonth() + 1;
var yyyy = date.getFullYear();
return mm + '/' + dd + '/' + yyyy;
}
function CalculateAge(dateString) {
var dtDOB = new Date(dateString);
var dtCurrent = new Date();
return dtCurrent.getFullYear() - dtDOB.getFullYear();
}
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" id="tblCustomers"></kendo-grid>
</body>
</html>
Screenshot