Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult GetAll()
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee { Id = 1, Name = "Category 1", IsEmployee = 1 });
employees.Add(new Employee { Id = 2, Name = "Category 2", IsEmployee = 0 });
employees.Add(new Employee { Id = 3, Name = "Category 3", IsEmployee = 1 });
return Json(employees, JsonRequestBehavior.AllowGet);
}
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public int IsEmployee { get; set; }
}
View
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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>
<style type="text/css">
body
{
font-family: Arial;
font-size: 12pt;
}
.switch
{
position: relative;
display: inline-block;
width: 45px;
height: 24px;
}
.switch input
{
opacity: 0;
}
.slider
{
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before
{
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 1px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider
{
background-color: #2196F3;
}
input:focus + .slider
{
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before
{
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
.slider.round
{
border-radius: 34px;
}
.slider.round:before
{
border-radius: 50%;
}
</style>
<script type="text/javascript">
var app = angular.module("MyApp", ["kendo.directives"]);
app.controller("MyController", function ($scope, $window, $http) {
$scope.mainGridOptions = {
dataSource: { transport: { read: "/Home/GetAll/" }, pageSize: 5 },
pageable: { refresh: true, pageSizes: [2, 25, 50] },
groupable: false,
sortable: true,
columns: [
{ field: "Id", title: "Id" },
{ field: "Name", title: "Name" },
{
template: function (dateItem) {
return dateItem.IsEmployee == 1 ?
"<label class='switch'><input type='checkbox' ng-click='chkClick($event," + dateItem.Id + ")' class='checkbox' ng-checked='" + dateItem.IsEmployee + "' /><span class='slider round'></span></label>" :
"<label class='switch'><input type='checkbox' ng-click='chkClick($event," + dateItem.Id + ")' class='checkbox'/><span class='slider round'></span></label>";
},
title: "Is Active"
}]
};
$scope.chkClick = function (event, id) {
var isChecked = event.currentTarget.checked;
$window.alert("Id : " + id + "\nChecked : " + isChecked);
};
})
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid options="mainGridOptions"></kendo-grid>
</body>
</html>
Screenshot