Dynamic Column Header(Title) in Kendo Grid MVC

1 Answer 786 Views
Grid
Chinonso
Top achievements
Rank 1
Chinonso asked on 26 Oct 2017, 01:37 PM

Hi there guys, i am trying to make the value of a column header(Title) different from what the column is bound to. So my grid have a few columns where the value displayed in the column is different from what the column header say. So instead of the title being static like.

columns.Bound(c => c.CurrentPlanStatus).ClientTemplate("<a href='"+ "Plan/EditTab" + "?pkid=#= ProjectKeyID #&pid=#=ProjectID #&fyid=#=CurrentFiscalYearID #&ptid=#=ProjectTypeID #&prgmid=#=ProgramID #'" + ">#=CurrentPlanStatus#</a>").Title("FY 18");

 

i want it  to be something like

columns.Bound(c => c.CurrentPlanStatus).ClientTemplate("<a href='"+ "Plan/EditTab" + "?pkid=#= ProjectKeyID #&pid=#=ProjectID #&fyid=#=CurrentFiscalYearID #&ptid=#=ProjectTypeID #&prgmid=#=ProgramID #'" + ">#=CurrentPlanStatus#</a>").Title("FY" + c => c.CurrentFiscalYear.ToString());

 

How do i go about doing this? thanks.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 30 Oct 2017, 09:22 AM
Hello, Chinonso,

Currently, the Grid only supports a HeaderTemplate, but this will not have access to the Grid values directly. This function approach can be used to call an external function which based on some calculations can display the desired result:

https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/GridColumnBuilderBase#methods-HeaderTemplate(System.Action)

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.headerTemplate

I can suggest submitting feature request describing, which values will be helpful inside the headerTemplate. Then based on its popularity we may implement them in a future release:

http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/category/170280-grid

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Chinonso
Top achievements
Rank 1
commented on 30 Oct 2017, 04:50 PM

Thanks for getting back to me, i will go ahead and submit a feature request. However, at the moment, i found a quick work around.

This is what i did 

columns.Bound(c => c.CurrentPlanStatus).ClientTemplate("<a href='"+ "Plan/EditTab" + "?pkid=#= ProjectKeyID #&pid=#=ProjectID #&fyid=#=CurrentFiscalYearID #&ptid=#=ProjectTypeID #&prgmid=#=ProgramID #'" + ">#=CurrentPlanStatus#</a>").HeaderTemplate(@<text> FY @ViewBag.CurrentFY </text>);

 

 

 

Tags
Grid
Asked by
Chinonso
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or