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

Grid Grouping by Foreign Key - Group header wrong

6 Answers 411 Views
Grid
This is a migrated thread and some comments may be shown as answers.
leniency
Top achievements
Rank 1
leniency asked on 22 Oct 2012, 11:22 PM
I'm trying to enable grouping by a foreign key column. However, a default Ajax setup will display the id of the column, not the display text for the group header. With server binding, the group header displays as expected. With Ajax binding however, it won't.

Using Kendo 2012.2.607. I know this used to work with Telerik, used it all the time.
@(Html.Kendo().Grid(Model.Users)
    .Name("Users")
    .DataSource(c => c.Ajax()
        .Read("_Roles", "Users")
        .Group(g => g.Add(o => o.RoleId)))
    .Columns(c => {
        c.Bound(o => o.UserName);
        c.ForeignKey(o => o.RoleId, Model.Roles);
        c.Bound(o => o.IsActive);
    })
    .Sortable()
    .Filterable()
    .Groupable()
    .Pageable())

With this, the group headers will read as "Role: 1", "Role: 2" and so on.  Expected "Role: Admin", "Role: User", etc. Can't really find any options to fix this. Trying to add a ClientGroupHeaderTemplate doesn't work either - always yields an error about whatever value being undefined. The anonymous function called to display the template has no real data to display the correct label.

c.ForeignKey(o => o.RoleId, Model.Roles)
.ClientGroupHeaderTemplate("#= Title #");

Edit - I setup a jsfiddle here to illustrate.

6 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 2
answered on 25 Oct 2012, 10:28 AM
With regards the ClientGroupHeaderTemplate giving an undefined error, I found that you just need to reference the value of the field rather than the name of the field, i.e.:

c.ForeignKey(o => o.RoleId, Model.Roles)
    .ClientGroupHeaderTemplate("#= value #");
0
leniency
Top achievements
Rank 1
answered on 25 Oct 2012, 02:47 PM
Thanks Andrew, but still doesn't work.  That still only prints out the value part, not the expected text part.  Ie, the headers are still numeric. Note that when doing purely server based rendering, it works fine - this is only an issue with client side.
0
loic lacomme
Top achievements
Rank 1
answered on 07 Nov 2012, 03:56 PM
I am having the same problem did you solve the issue?
0
leniency
Top achievements
Rank 1
answered on 13 Nov 2012, 03:33 PM
Nope, nothing yet.  The 2012.3.1024 beta doesn't solve the issue.
0
Lee
Top achievements
Rank 1
answered on 31 May 2018, 02:46 PM

I'm having same issue.  Has anyone solved this.  I'm using a foreignkey column tthat looks like this;

columns.ForeignKey(p => p.EmployeeID, (System.Collections.IEnumerable)ViewData["Employees"], "ID", "EmployeeName")

When I group by EmployeeID I get the numeric value of EmployeeID on the group header.  What I want it to show is the EmployeeName.   My ClientGroupHeaderTemplate looks like this:

 

.ClientGroupHeaderTemplate("Employee: #= value # (Count: #=count#)")

 

0
Konstantin Dikov
Telerik team
answered on 05 Jun 2018, 12:11 PM
Hello Lee,

The ForeignKey column will handle the group headers internally, but once a template is used, that internal logic will not be applied, so you will have to get reference to the "values" collection of the foreignkey column and manually find the corresponding text value. I have create a dojo example with such implementation:
Hope this helps.


Regards,
Konstantin Dikov
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.
Tags
Grid
Asked by
leniency
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 2
leniency
Top achievements
Rank 1
loic lacomme
Top achievements
Rank 1
Lee
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or