Dynamic Column Header(Title) in Kendo Grid MVC

3 posts, 0 answers
  1. Chinonso
    Chinonso avatar
    48 posts
    Member since:
    Jan 2017

    Posted 26 Oct 2017 Link to this post

    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.

  2. Stefan
    Admin
    Stefan avatar
    2956 posts

    Posted 30 Oct 2017 Link to this post

    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.
  3. Chinonso
    Chinonso avatar
    48 posts
    Member since:
    Jan 2017

    Posted 30 Oct 2017 in reply to Stefan Link to this post

    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>);

     

     

     

Back to Top