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", Age = 60 });
customers.Add(new Customer { Id = 2, Name = "Mudassar Khan", Age = 36 });
customers.Add(new Customer { Id = 3, Name = "Suzanne Mathews", Age = 65 });
customers.Add(new Customer { Id = 4, Name = "Robert Schidner", Age = 70 });
return Json(customers, JsonRequestBehavior.AllowGet);
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style type="text/css">
.error {
color: red;
}
</style>
<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, $http, $window, $interval) {
$scope.mainGridOptions = {
dataSource: {
type: "json",
transport: {
read: { url: "/Home/GetCustomers" }
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, nullable: true, type: "number" },
Name: { editable: true, nullable: true, type: "string" },
Age: { editable: true, nullable: true, type: "string" }
}
}
},
pageSize: 4,
serverPaging: false,
serverSorting: false
},
editable: "inline",
sortable: true,
pageable: true,
resizeable: true,
columns: [
{ field: "Id", title: "Id", width: '60px' },
{
field: "Age",
template: '<input style="width:120px" type="text" id="Age" class="age" onkeyup="currencyNumber(3)(this);ValidateMaxMin(this,18,60);" />',
width: 150
}
],
toolbar: ["create"],
dataBound: function (e) {
var grid = e.sender;
var items = e.sender.items();
items.each(function (e) {
var dataItem = grid.dataItem(this);
var txtAge = $(this).find('.age');
$(txtAge).val(dataItem.Age);
});
},
edit: function (e) {
if (e.model.isNew()) {
$(e.container.find("input[name=Age]")).attr('onkeyup', 'currencyNumber(3)(this);ValidateMaxMin(this,18,60);')
}
}
};
});
function ValidateMaxMin(element, min, max) {
var value = $.trim($(element).val());
if ($(element).parent().find('span') != undefined || $(element).parent().find('span') != null) {
$(element).parent().find('span').remove();
}
if (value < min || value > max) {
//alert('Max 60 and min 18 allowed.');
$(element).parent().append('<span class="error"><br />Max 60 and min 18 allowed.</span>');
}
}
function currencyNumber(decimals) {
if (typeof decimals !== 'number') {
decimals = 2;
}
return function (e) {
var input = $(this instanceof Window ? e : e.currentTarget);
var value = $.trim(input.val());
var hasNegativeNumber = value.substr(0, 1) === '-' ? '-' : '';
var nextValue = value.replace(/\.+/g, '.').replace(/[^0-9\.]+/g, '');
if (nextValue === '.' || (nextValue.length > 1 && nextValue === "00")) {
nextValue = '';
}
var dotsFound = nextValue.split('.').filter(function (i) {
return i.length;
});
var afterDot = '';
var beforeDot = '';
if (dotsFound.length > 1) {
beforeDot = dotsFound[0];
dotsFound.splice(0, 1);
afterDot = dotsFound.join('');
nextValue = +(beforeDot) + '.' + afterDot.substr(0, decimals);
}
if (nextValue.substr(nextValue.length - 1, 1) === '.') {
input.one('change', function () {
if (nextValue.substr(nextValue.length - 1, 1) === '.') {
nextValue = nextValue.substr(0, nextValue.length - 1);
input.val(hasNegativeNumber + nextValue);
}
$(this).off('change');
})
} else {
input.off('change')
}
input.val(hasNegativeNumber + nextValue);
};
}
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" id="tblCustomers"></kendo-grid>
</body>
</html>
Screenshot