This is a migrated thread and some comments may be shown as answers.

ClientGroupHeaderTemplate not picking up data

5 Answers 1413 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 08 Nov 2016, 11:15 AM
Hi All,

I'm having problems when trying to add a clickable hyperlink to my header template on my grid. The idea is to add a hyperlink with the text of ClientName from the dataitem that will call my controller and pass the ClientCode of the underlying data item.

 
.Columns(columns =>
{
    columns.Bound(u => u.ClientName)
           .ClientGroupHeaderTemplate(Html.ActionLink("\"<#= ClientName#>\"", "blalbalba", "blabla", new { clientCode = "<#= ClientCode #>" }).ToString());
    columns.Bound(u => u.Status).Width("50px").Title("Collat").ClientTemplate("<i class='#= Status ? 'fa fa-check fa-3x red-text' : 'fa' #'/>");
    columns.Bound(u => u.Quantity).Width("100px");
    columns.Bound(u => u.Security).Title("Security");
    columns.Bound(u => u.Value).Format("{0:C}")
        .ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
         .ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Width("100px");
    columns.Bound(u => u.CollatValue).Format("{0:C}")
        .ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
        .ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Title("Collat. Value").Width("100px");
 
})
.NoRecords("No records found")
.Pageable(pageable => pageable.Refresh(true))
.Sortable()
.Navigatable()
.AutoBind(true)
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
    aggregates.Add(p => p.Value).Sum();
    aggregates.Add(p => p.CollatValue).Sum();
}).Group(group => group.Add(x => x.ClientName))
.PageSize(100)

 

cheers

5 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 10 Nov 2016, 08:07 AM
Hi Mark,

You can find the list with the fields which can be used in the groupHeaderTemplate here - http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.groupHeaderTemplate

Regards,
Danail Vasilev
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Tim Weckx
Top achievements
Rank 2
answered on 08 Aug 2018, 03:11 PM

I'm trying something similar. In the ClientTemplate, you can access all other fields (see code below). Is there any way this is possible with the ClientGroupHeaderTemplate? From the documentation link, it seems the only value available is the value from the field that the column is bound to. In the below code for the ClientGroupHeaderTemplate, I can replace #=ContractName# with #=value#, but what do I need to change #=ContractId# to? I've debugged into the javascript as well, and the 'data' object doesn't seem to provide any other data.

 

c.Bound(x => x.ContractName).Title("Contract")
        .ClientTemplate(@Html.ActionLink("#=ContractName#", "Index", "Contract", new { ID = "#=ContractId#" }, null).ToHtmlString())
        .ClientGroupHeaderTemplate("Contract: " + @Html.ActionLink("#=ContractName#", "Index", "Contract", new { ID = "#=ContractId#" }, null).ToHtmlString());

0
Tsvetina
Telerik team
answered on 10 Aug 2018, 02:30 PM
Hi Tim,

When grouping by a field, only this field value is expected to have the same value for all data items. For the rest of the fields, there isn't a single value to return in the template. Therefore, the template contains an items variable, which contains all data items that belong to the group:
items - the data items for current group. Returns groups if the data items are grouped (in case there are child groups)

If your Grid is grouped by ContractName and there is one ContractId value per one ContractName, then it does not matter from which item in the group you will get the ContractId. You can try the following:
.ClientGroupHeaderTemplate("Contract: " + @Html.ActionLink("#=ContractName#", "Index", "Contract", new { ID = "#=items[0].ContractId#" }, null).ToHtmlString());


Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Tim Weckx
Top achievements
Rank 2
answered on 15 Aug 2018, 12:06 AM

I'm trying something similar. In the ClientTemplate, you can access all other fields (see code below). Is there any way this is possible with the ClientGroupHeaderTemplate? From the documentation link, it seems the only value available is the value from the field that the column is bound to. In the below code for the ClientGroupHeaderTemplate, I can replace #=ContractName# with #=value#, but what do I need to change #=ContractId# to? I've debugged into the javascript as well, and the 'data' object doesn't seem to provide any other data.

 

c.Bound(x => x.ContractName).Title("Contract")
        .ClientTemplate(@Html.ActionLink("#=ContractName#", "Index", "Contract", new { ID = "#=ContractId#" }, null).ToHtmlString())
        .ClientGroupHeaderTemplate("Contract: " + @Html.ActionLink("#=ContractName#", "Index", "Contract", new { ID = "#=ContractId#" }, null).ToHtmlString());

0
Tsvetina
Telerik team
answered on 15 Aug 2018, 02:46 PM
Hi Tim,

The information and code snippet I shared in my last post refer to the ClientGroupHeaderTemplate. Since R2 2017 release (2017.2.504), there is an items property in the groupHeaderTemplate (MVC ClientGroupHeaderTemplate), which contains the data items for the current group.
.ClientGroupHeaderTemplate("Contract: " + @Html.ActionLink("#=value #", "Index", "Contract", new { ID = "#=items[0].ContractId#" }, null).ToHtmlString());

If such a property is not available, then you are probably using an older version of Kendo UI and should consider upgrading to R2 2017 or newer.


Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Tim Weckx
Top achievements
Rank 2
Tsvetina
Telerik team
Share this question
or