change group header dynamically in kendo ui mvc - asp.net-mvc

I am using kendo ui with asp.net mvc. I want to change the group header coloumn dynamically. Please suggest solution.My code is shown below.
<div id="dvPayrollReportGrid" class="kendo-responsive-grid-content">
#(Html.Kendo().Grid<CyberPayBO.Models.PayrollReportModel>()
.Name("gridpayrollreport")
.Columns(columns =>
{
columns.Bound(payroll => payroll.CompanyCode).Title("").Hidden(true).Filterable(false).ClientTemplate("<input type='hidden' id='hdnCompanyCode' value='#=CompanyCode#'>");
columns.Bound(payroll => payroll.CompanyCode).Title("Action").Filterable(false).ClientTemplate("View || <span class='CompanyNameLink DeleteLink' onclick='DeletePayrollReport(this.id)' id='#=ID#'>Del</span> | <img src='../Images/pdf.gif' id='PayrollImage'/>").Sortable(false);
columns.Bound(payroll => payroll.CheckDate).Format("{0:dd/MM/yyyy}");
columns.Bound(payroll => payroll.FromDate).Format("{0:dd/MM/yyyy}");
columns.Bound(payroll => payroll.ToDate).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.StoredFile).ClientTemplate("#if (StoredFile.toLowerCase().indexOf('.pdf')>-1) {#"
+ " "
+ "#} else { #" + ""
+ "# } #" + "#=StoredFile#");
columns.Bound(payroll => payroll.CheckDate).Title("Payroll Reports").Hidden(Convert.ToBoolean(PayrollReportColumn)).ClientTemplate("<span style='color:red'>Payroll Report</span>");
columns.Bound(payroll => payroll.CreatedDate).Title("Created At").Format("{0:dd/MM/yyyy HH:mm tt}");
})
.Pageable(pageable => pageable
.Messages(messages => messages.Display("Payroll Reports {0} - {1} of {2}"))
)
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(PageSize)
.Read(read => read.Action("PayrollReport_Read", "PayrollReport"))
.Group(groups =>
{
groups.Add(payroll => payroll.CompanyName);
})
)
)
</div>
i am grouping by the company name, and by default it is giving me company name as header in result. I want the header to be dynamic and display the company code instead.I am getting ouput as CompanyName: AAA TEST 1 in header, but i want ouput as 004:AAA Test 1., where 004 is company code.

I found the solution to it by using ClientGroupHeader Template
columns.Bound(payroll => payroll.Company).ClientGroupHeaderTemplate("#=value#").Hidden(true);
Here company is combination of CompanyCode and CompanyName and which i bind from repository. Finally grouping on Company gives me the desired result.

To Achieve this you need to return a new column in your backend With the class of the data you want to group by since Kendo doesn't let you group by anonymous type yet. the End the end of your Action will look something like this
...
var query = db.PayrollReportModel.Select(payroll=> new PayrollReportModel()
{
payroll.CompanyCode
...
grouper = new GrouperClass()
{
CompanyCode = payroll.CompanyCode,
CompanyName = payroll.CompanyName
}
});
DataSourceResult result = await query.ToDataSourceResultAsync(request);
}
For your View
<div id="dvPayrollReportGrid" class="kendo-responsive-grid-content">
#(Html.Kendo().Grid<CyberPayBO.Models.PayrollReportModel>()
.Name("gridpayrollreport")
.Columns(columns =>
{
columns.Bound(payroll => payroll.grouper).Hidden(true).ClientGroupHeaderTemplate("#=value.CompanyCode#-#=value.CompanyName#");
columns.Bound(payroll => payroll.CompanyCode).Title("Action").Filterable(false).ClientTemplate("View || <span class='CompanyNameLink DeleteLink' onclick='DeletePayrollReport(this.id)' id='#=ID#'>Del</span> | <img src='../Images/pdf.gif' id='PayrollImage'/>").Sortable(false);
columns.Bound(payroll => payroll.CheckDate).Format("{0:dd/MM/yyyy}");
columns.Bound(payroll => payroll.FromDate).Format("{0:dd/MM/yyyy}");
columns.Bound(payroll => payroll.ToDate).Format("{0:dd/MM/yyyy}");
columns.Bound(p => p.StoredFile).ClientTemplate("#if (StoredFile.toLowerCase().indexOf('.pdf')>-1) {#"
+ " " + "#} else { #" + "" + "# } #" + "#=StoredFile#");
columns.Bound(payroll => payroll.CheckDate).Title("Payroll Reports").Hidden(Convert.ToBoolean(PayrollReportColumn)).ClientTemplate("<span style='color:red'>Payroll Report</span>");
columns.Bound(payroll => payroll.CreatedDate).Title("Created At").Format("{0:dd/MM/yyyy HH:mm tt}");
})
.Pageable(pageable => pageable
.Messages(messages => messages.Display("Payroll Reports {0} - {1} of{2}"))
)
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(PageSize)
.Read(read => read.Action("PayrollReport_Read", "PayrollReport"))
.Group(groups =>
{
groups.Add(payroll => payroll.grouper);
})
)
)
</div>
Hope this helps

Related

Kendo MVC Grid will not hide columns with media query

My Kendo grid incorrectly displays the responsive column when the page is viewed on a desktop (width > 2000px). My grid code is below. It seems like .Media("(max-width: 450px)"); in the last column doesn't work. It renders fine on a small screen. Only the last column is displayed.
<% Html.Kendo().Grid<WWT.Models.GageList>()
.Name("StationGrid")
.Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single))
.Filterable(filter =>
{
filter.Extra(false);
filter.Operators(op =>
{
op.ForString(str => str.Clear());
op.ForString(str =>
{
str.Clear().Contains("Contains");
});
});
filter.Mode(GridFilterMode.Row);
})
.Sortable(a => a.Enabled(true))
.Events(events => events
.DataBound("onDataBound")
.Change("AddRowClick")
)
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("IndexReplaceStation", "Window", new { company = Model.company, gageSN = Model.id, model = Model.model }).Data("GridSearchData"))
.PageSize(20)
)
.Columns(columns =>
{
columns.Bound(c => c.ModelNumber).Title("Model").HtmlAttributes(new { #class = "telerikGridCell" }).MinScreenWidth(450);
columns.Bound(c => c.SID).Title("SID").HtmlAttributes(new { #class = "telerikGridCell" }).MinScreenWidth(450);
columns.Bound(c => c).ClientTemplate("#=resColTemplate(data)#").Title("").Media("(max-width: 450px)");
})
.Scrollable(scrolling => scrolling.Height(150))
.Render();
%>
</div>
<script id="responsive-column-template" type="text/x-kendo-template">
<strong>Model</strong>
<p class="col-template-val">#=data.ModelNumber#</p>
<strong>SID</strong>
<p class="col-template-val">#=data.SID#</p>
</script>
I use min-width at 320 and 850px breakpoints.
cols.Bound(x => x.SectionCode)
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Media("(min-width: 320px)")
.Width("25%");

Set page size to all on load on a kendo grid

I have a simple question I cannot seem to find the answer to. I would like the grid to default to show all results on load. If possible even take out the paging at the bottom but I cannot seem to find it anywhere.
This is my grid:
#(Html.Kendo().Grid<Website.Models.LinesForPayType.LinesForPayTypeGridModel>()
.Name("gridAssignLines")
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(new { #id = "CreatePaymentTypeLine", #style = "display:inline-block;" });
toolbar.Save().SaveText("Create Invoice").HtmlAttributes(new { id = "create-invoice", href = "#" }); ;
})
.Columns(columns =>
{
columns.Select().Width(30);
columns.Bound(c => c.Description);
columns.Bound(c => c.LineNo);
columns.Bound(c => c.Quantity);
columns.Bound(c => c.UnitPrice)
.ClientTemplate(Model.HomeCurrencySymbol + " #=kendo.toString(UnitPrice ? UnitPrice : 0,'n2')#");
columns.Bound(c => c.Total)
.ClientTemplate(Model.HomeCurrencySymbol + " #=kendo.toString(Total ? Total : 0,'n2')#");
})
.Events(e => e.DataBound("AddStudentController.onCheckClick"))
.Pageable(page => page
.Refresh(true)
.PageSizes("All")
)
.Editable(edit => edit.Mode(GridEditMode.InCell))
.Scrollable()
.Events(events => events.Save("AddStudentController.onInvoiceGridSave"))
.Reorderable(reorder => reorder.Columns(true))
.NoRecords("No data")
.Filterable(f => f.Operators(o => o.ForString(fs => fs.Clear().Contains("Contains").StartsWith("Start With").EndsWith("End with").IsEqualTo("Is equal to").IsNotEqualTo("Is not equal to"))))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Sort(s =>
{
s.Add(a => a.LineNo).Ascending();
})
.Model(model =>
{
model.Id(i => i.ID);
})
.Read(read => read.Action("ReadPaymentTypeLines", "Payment").Data("AddStudentController.getPaymentTypeID"))
.Create(create => create.Action("CreatePaymentTypeLines", "Payment"))
.Update(update => update.Action("CreatePaymentTypeLines", "Payment"))
)
)
Set the datasource's PageSize to int.MaxValue (e.g. https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/GridBuilder#datasourcesystemstring) and if you don't want to see the paging stuff, set Pageable to false.

EditCell with widgets Kendo Grid MVC

I have a grid with some editor templates. The grid can be edited InCell.
I want to change the edit inCell event so that it will edit the values on double click. Untill now I have done it like this :
$(table + " table").on("dblclick",
"tbody>tr>td",
function(e) {
var grid = $(table).data("kendoGrid");
grid.editCell($(this));
});
The problem that I have is that when I double click on the cell, the widget that I want for editing (Multiselect, DropdownList ...) is not rendered in the grid and looks like this :
Instead, it should look like this:
One of the editors looks like this :
#(Html.Kendo().DropDownList()
.Name("Responsible")
.DataTextField("ResponsibleName")
.DataValueField("ResponsibleId")
.BindTo((System.Collections.IEnumerable)ViewData["Responsible"])
);
The definition of the grid is :
#(Html.Kendo().Grid(Model.ActivitiesList)
.Name(Model.ActivitiesSection)
.ClientDetailTemplateId(Model.ActivitiesSection + "-description")
.Columns(columns =>
{
columns.Bound(c => c.ActivityId).Title(#Html.Kendo().CheckBox().Name("check-#=ActivitiesSection#").Checked(false).Enable(false).ToString()).ClientTemplate(#Html.Kendo().CheckBox().Name("check-#=ActivityId#").Checked(false).ToString()).Sortable(false);
columns.Bound(c => c.StatusColor).Title("").ClientTemplate("<i class='fa fa-circle' aria-hidden='true' style='font-size: smaller; color:#=StatusColor#;'></i>").Sortable(false);
columns.Bound(c => c.StatusDescription).Title("Status").ClientTemplate("#=StatusDescription#");
columns.Bound(c => c.Name).Title("Name").ClientTemplate("<p class='activity-name'>#=Name#</p>");
columns.Bound(c => c.Priority).Title("Priority").ClientTemplate("#=PriorityTemplate(Priority)#");
columns.Bound(c => c.Responsible).Title("Responsible").HtmlAttributes(new { #class = "templateCell" }).ClientTemplate("#=ResponsibleTemplate(Responsible)#");
columns.Bound(c => c.Team).Title("Team").ClientTemplate("Better solutions");
columns.Bound(c => c.GeographicResponsibility).Title("Geographic Resp").HtmlAttributes(new { #class = "templateCell" }).ClientTemplate("#=GeographicResponsibilityTemplate(GeographicResponsibility)#").EditorTemplateName("_GeographicalResponsibilityEditor");
columns.Bound(c => c.FunctionOrPracticeResponsible).Title("Function/Practice Resp").HtmlAttributes(new { #class = "templateCell" }).ClientTemplate("#=FunctionOrPracticeResponsibleTemplate(FunctionOrPracticeResponsible)#").EditorTemplateName("_FunctionResponsibleEditor");
columns.Bound(c => c.DueDate).Title("Due date").ClientTemplate("<p style='white-space: nowrap'>#= DueDate != null ? kendo.toString(kendo.parseDate(DueDate,'dd/MM/yyyy'), 'dd-MM-yyyy') : 'DD-MM-YY' #</p>").EditorTemplateName("_ActivityDueDateEditor");
columns.Bound(c => c.Starred).Title("<i class='fa fa-star' aria-hidden='true' style='color: #ededed; font-size:large;'></i>").ClientTemplate("<i class='fa fa-star' aria-hidden='true' style='color:\\#ededed;'></i>").Sortable(false);
columns.Bound(c => c.StatusDescription).Title("<i class='fa fa-file' aria-hidden='true' style='color: #ededed; font-size:large'></i>").ClientTemplate("<i class='fa fa-file' aria-hidden='true' style='color:\\#ededed;'></i>").Sortable(false);
columns.Bound(c => c.ActivityId).Title("").ClientTemplate("<input type='button' value='More Info' class='expanded-section' id='#= ActivityId #'/>").Sortable(false);
columns.Bound(c => c.ActivityId).Title("").ClientTemplate("<input type='hidden' class='js-activity-id' value='#= ActivityId #'").Sortable(false);
columns.Bound(c => c.KeyLaunchElementId).Hidden(true);
columns.Bound(c => c.ProcessMapId).Hidden(true);
columns.Bound(c => c.WorkstreamId).Hidden(true);
})
.DataSource(e => e.Ajax().ServerOperation(false).Sort(a => a.Add("Name").Ascending())
.Model(model =>
{
model.Id(act => act.ActivityId);
model.Field(act => act.Name);
model.Field(act => act.ActivityId).Editable(false);
model.Field(act => act.Priority).DefaultValue(new ActivityPriorityViewModel());
model.Field(act => act.StatusColor).Editable(false).DefaultValue("#00b0d3");
model.Field(act => act.StatusDescription).DefaultValue("New").Editable(false);
model.Field(act => act.Responsible).DefaultValue(new ActivityResponsibleViewModel());
model.Field(act => act.Team).Editable(false);
model.Field(act => act.GeographicResponsibility).DefaultValue(new GeographicalResponsibilityViewModel());
model.Field(act => act.FunctionOrPracticeResponsible).DefaultValue(new List<FunctionOrPracticeViewModel>());
model.Field(act => act.DueDate);
model.Field(act => act.Starred).Editable(false);
})
.Update(update => update.Action("UpdateActivity", "Activity"))
.AutoSync(true))
.Events(events => events.DetailExpand("detailExpand").Save("function(e) { this.dataSource.sync() }").DataBound("activityFilter.IsSorted"))
.Sortable(s => s.SortMode(GridSortMode.SingleColumn).AllowUnsort(false))
.Editable(edit => edit.Mode(GridEditMode.InCell))
)
Thank you!
At first create new editor and place it under directory: Views/Shared/EditorTemplates directory. I created "DropdownTest.cshtml" editor:
#using Kendo.Mvc.UI
#(
Html.Kendo().DropDownListFor(m => m)
.BindTo((System.Collections.IEnumerable)ViewData["Responsible"])
.DataValueField("ResponsibleId")
.DataTextField("ResponsibleName")
)
ViewData["Responsible"] is used to list all of positions while editing, so it must be initialized in view method:
public ActionResult Index()
{
ViewData["Responsible"] = new List<Responsible>()
{
new Responsible
{
ResponsibleId = 1,
ResponsibleName = "Test-A"
},
new Responsible
{
ResponsibleId = 2,
ResponsibleName = "Test-B"
}
};
return View();
}
A grid wrapper column definition (instead of bound - use foreign key):
columns.ForeignKey(p => p.Responsible.ResponsibleId, (System.Collections.IEnumerable)ViewData["Responsible"],
"ResponsibleId", "ResponsibleName").EditorTemplateName("DropdownTest");
EditorTemplateName("DropdownTest") is linked to editor from EditorTemplates directory.

Telerik Kendo MVC Grid - How do I set onload/initial filter equals True with checkbox columns?

I've been charged with changing my company's current webforms site pages to MVC. We use the Telerik tools package and I am looking for a way to set an initial filter on my grid so that when the page is loaded the grid defaults to showing only records that are checked (true). I have found several questions similar to this but so far none of the answers I have found in those instances dealt with checkboxes.
The code below is my "Active?" = True/False column in the MVC grid. I'm checking the deleted date for each record, which is treated as "deactivated" when a delete date exists. My user-initiated filtering works great on the grid but I am having trouble figuring out how to set the initial filter value on this column to TRUE while also allowing the user to clear the filter to then view deactivated records along with the active records.
I appreciate any help you can offer. If I'm implementing this completely wrong, feel free to let me know, but please also include an example of the correct way to accomplish this functionality.
columns.Bound("DeleteDateUTC")
.ClientTemplate("<input type='checkbox' #= kendo.parseDate(DeleteDateUTC) ? '' : checked='checked' # disabled='disabled' />")
.Title("Active?")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Is equal to")))
.Width(100);
Thank you!
EDIT 1:
<div id="gridArea" class="k-virtual-scrollable-wrap">
#(Html.Kendo().Grid<dynamic>()
.Name("OperatorsGrid")
.Mobile(MobileMode.Auto)
.Pageable(pager => pager.PageSizes(new int[] { 50, 100, 250 })
.Refresh(true))
.Sortable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height: 800px;" })
.Scrollable()
.ColumnMenu()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Events(e => e.DataBound("onDataBound").Cancel("onCancel"))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id("ID");
})
.PageSize(100)
.Read(read => read.Action("Operators_Read", "TableMx"))
)
.Columns(columns =>
{
columns.Command(cmd => cmd.Custom("Operators_Edit").Text(" ").Click("edit"))
.Title("Edit")
.Width(75);
columns.Command(cmd => cmd.Custom("Operators_Deactivate").Text(" ").Click("deactivate"))
.Title("Deactivate")
.Width(100);
columns.Bound("DeleteDateUTC")
.ClientTemplate("<input type='checkbox' #= kendo.parseDate(DeleteDateUTC) ? '' : checked='checked' # disabled='disabled' />")
.Title("Active?")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Is equal to")))
.Width(100);
columns.Bound("Name")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Title("Name")
.Width(350);
columns.Bound("Address")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Title("Address")
.Width(250);
columns.Bound("City")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Title("City")
.Width(150);
columns.Bound("StateAbbrev")
.Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)))
.Title("State")
.Width(100);
columns.Bound("Zip")
.Filterable(false)
.Title("Zip")
.Width(70);
columns.Bound("ContactName")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Title("Contact Name")
.Width(175);
columns.Bound("ContactEmail")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Title("Email")
.Width(175);
columns.Bound("ContactPhone")
.Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)))
.Title("Phone")
.Width(150);
columns.Bound("CreateDateUTC")
.ClientTemplate("#= kendo.parseDate(CreateDateUTC) ? (kendo.toString(kendo.parseDate(CreateDateUTC), 'MM/dd/yyyy h:mm tt')) : '' #")
.Title("Create Date UTC")
.Width(250);
columns.Bound("CreatedByUser")
.Title("Created By")
.Width(150);
columns.Bound("LastChangeDateUTC")
.ClientTemplate("#= kendo.parseDate(LastChangeDateUTC) ? (kendo.toString(kendo.parseDate(LastChangeDateUTC), 'MM/dd/yyyy h:mm tt')) : '' #")
.Title("Last Update Date UTC")
.Width(250);
columns.Bound("LastChangedByUser")
.Title("Last Updated By")
.Width(150);
columns.Bound("DeleteDateUTC")
.ClientTemplate("#= kendo.parseDate(DeleteDateUTC) ? (kendo.toString(kendo.parseDate(DeleteDateUTC), 'MM/dd/yyyy h:mm tt')) : '' #")
.Title("Deleted Date UTC")
.Width(250);
columns.Bound("DeletedByUser")
.Title("Deleted By")
.Width(150);
})
)
EDIT 2:
Adding script section below grid. I'm not sure if this is required in order to help me out but it can't hurt to see everything that's going on.
<script>
$(function () {
var grid = $("#OperatorsGrid").data("kendoGrid");
//Save personalized settings for this grid (columns shown, etc.)
$("#save").click(function (e) {
e.preventDefault();
localStorage["kendo-grid-options"] = kendo.stringify(grid.getOptions());
});
//If the user has saved options, load them. Otherwise, load the default filter for the active column
var options = localStorage["kendo-grid-options"];
if (options) {
grid.setOptions(JSON.parse(options));
}
else {
grid.dataSource.filter({ field: "Active?", operator: "eq", value: "checked" });
}
//Remove column menu from any columns specified by data-title below:
//grid.thead.find("[data-title=columnTitleHere]>.k-header-column-menu").remove();
grid.thead.find("[data-title=\"Active?\"]>.k-header-column-menu").remove();
});
function deactivate(e) {
e.preventDefault();
var id = this.dataItem($(e.currentTarget).closest("tr")).id;
var url = "/TableMx/Operators_Deactivate/" + id;
$.ajax({
type: "POST",
url: url,
})
.done(function () {
// refresh the grid to remove the just deactivated order
refreshGrid();
})
.fail(function () { alert("failure deactivating operator") })
}
function edit(e) {
}
function onDataBound(e) {
$(".k-grid-Operators_Deactivate span").addClass("k-icon k-delete ob-icon-only");
$(".k-grid-Operators_Edit span").addClass("k-icon k-edit ob-icon-only");
}
function onCancel(e) {
e.preventDefault();
e.sender.refresh();
}
function refreshGrid() {
if ($(".k-i-refresh").length > 0) {
$(".k-i-refresh").trigger('click');
}
}
Instead of using a dynamic model, create a view model like this:
public class OperatorViewModel
{
// I'm not sure if your ID is int or string...
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
// All the other properties here
// ...
// ...
[Display(Name = "Active?")]
public bool IsActive { get; set; }
}
As you see, I also added an IsActive property to the view model. You'll populate this property in your Controller, depending on whether there is a DeleteDateUTC or not.
Then, your grid will be like (Note the .Filter I added to your data source):
#(Html.Kendo().Grid<YourApp.ViewModels.OperatorViewModel>()
.Name("OperatorsGrid")
.Mobile(MobileMode.Auto)
.Pageable(pager => pager.PageSizes(new int[] { 50, 100, 250 })
.Refresh(true))
.Sortable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height: 800px;" })
.Scrollable()
.ColumnMenu()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Events(e => e.DataBound("onDataBound").Cancel("onCancel"))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id("ID");
})
// THIS IS WHERE YOU FILTER THE IsActive FIELD
.Filter(f => f.Add(m => m.IsActive.Equals(true)))
.PageSize(100)
.Read(read => read.Action("Operators_Read", "TableMx"))
)
.Columns(columns =>
{
columns.Command(cmd => cmd.Custom("Operators_Edit").Text(" ").Click("edit"))
.Title("Edit")
.Width(75);
columns.Command(cmd => cmd.Custom("Operators_Deactivate").Text(" ").Click("deactivate"))
.Title("Deactivate")
.Width(100);
columns.Bound(c => c.IsActive)
.ClientTemplate("<input type='checkbox' #= IsActive ? '' : checked='checked' # disabled='disabled' />")
.Filterable(ftb => ftb.Cell(cell => cell.Operator("Is equal to")))
.Width(100);
columns.Bound(c => c.Name)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Width(350);
columns.Bound(c => c.Address)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Width(250);
columns.Bound(c => c.City)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")))
.Width(150);
//...
//...
Make sure your Operators_Read action returns a JSON of IEnumerable<OperatorViewModel>.

kendoui ClientTemplate in Grid not working in asp.net mvc 4

I have been looking all over for the answer and think I am missing something simple. I have a kendo grid where I want one of the columns to be a link to another page with the id as a route parameter. However, the value in the column cells are the bound values and are unchanged by my template. Any insights to this will be appreciated.
#(Html.Kendo().Grid((IEnumerable<ProviderAccess>)Model.Providers)
.Name("grants-grid")
.Columns(columns =>
{
columns.Bound(a => a.ProviderName);
columns.Bound(a => a.HasAccess);
columns.Bound(a => a.ProviderId).ClientTemplate("#= toggleLink(data) #");
})
.Scrollable()
)
<script>
function toggleLink(access) {
var action = '#Url.Action("Toggle", "Access")';
var html = kendo.format("<a href='{0}/{1}'>Toggle...</a>",
action,
access.ProviderId
);
return html;
}
</script>
ClientTemplate isn't using when Kendo Grid is binded to a dataSource on server side like your code.
You should use Template method of columns like below
columns.Template(p => "<a href='..../Toggle/Access/" + p.ProviderId + "'>Click</a>");
dataSource.Server() will let you use a custom.template
dataSource.Ajax() will let you use ClientTemplate
Figuring that out was really frustrating... They are not interchangeable one of the other will work depending on ajax or Server
<%: Html.Kendo().Grid((List<RadCarePlus.V2.Web.Models.GetMeSomeData>) ViewData["Mydata"])
.Name("Grid")
.Columns(columns =>
{
columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>").Title("Testing").Width(140);
//columns.Bound(c => c.EpisodeID).Width(140);
columns.Bound(c => c.AuthStatus).Width(190);
columns.Bound(c => c.CPTCode).Width(100);
columns.Bound(c => c.inscarrier).Width(110);
columns.Bound(c => c.CreatedOn).Width(160);
//columns.Template(c => "<a href='ImplementationDetails?EpisodeID=" + c.EpisodeID + "'>" + c.EpisodeID + "</a>");
//columns.Template(c => c.EpisodeID).Title("Testing").ClientTemplate("<a href='ImplementationDetails?EpisodeID=#= EpisodeID#'>#= EpisodeID #</a>");
})
.Pageable(pageable=> pageable.ButtonCount(5))
.Sortable(sortable => sortable.AllowUnsort(false))
.DataSource(dataSource => dataSource.Server().PageSize(5)
)
%>

Resources