Try using the code snippet below.
VIEW
@model MvcApplication1.Models.TestModels <script type="text/javascript"> var rowNumber = 0; function resetRowNumber(e) { rowNumber = 0; } function renderNumber(data) { return ++rowNumber; } function renderRecordNumber(data) { var page = parseInt($("#Grid").data("kendoGrid").dataSource.page()) - 1; var pagesize = $("#Grid").data("kendoGrid").dataSource.pageSize(); return parseInt(rowNumber + (parseInt(page) * parseInt(pagesize))); } </script> @(Html.Kendo().Grid<MvcApplication1.Models.TestModels>() .Name("Grid") .Columns(columns => { columns.Bound(p => p.ID); columns.Bound(p => p.Name); columns.Template(t => { }).Title("Row No").ClientTemplate("# if ( '" + @Model.Permissions.HasValue.ToString().ToLower() + "' == 'true') { #" + "<input type='text' name='MyViewModels.Index' value='#= renderNumber(data) #' /> " + "# } #"); }) .Pageable(x => x.PageSizes(new int[] { 10, 20, 30, 50 }).Refresh(true)) .Sortable() .Filterable() .DataSource(dataSource => dataSource .Ajax() .Read(read => read.Action("Grid_Read", "Home")) ) .Events(ev => ev.DataBound("resetRowNumber")) )
CONTROLLER
public ActionResult Index() { TestModels model = new TestModels(); model.Permissions = true; //Please comment this line and check return View(model); } public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request) { List<TestModels> models = new List<TestModels>(); for (int i = 0; i < 50; i++) { TestModels t1 = new TestModels(); t1.ID = i; t1.Name = "Name" + i; models.Add(t1); } return Json(models.ToDataSourceResult(request)); }
MODEL
public class TestModels { [Display(Name = "ID")] public int ID { get; set; } [Display(Name = "Name")] public string Name { get; set; } public bool? Permissions { get; set; } }
Try using the code snippet above. Let me know if there is any problem.
source share