¿Cómo puedo mostrar un valor de modelo no agregado en un encabezado agregado de Telerik MVC Grid?

Mi cuadrícula:

    @( Html.Telerik().Grid<eGate.BackOffice.Core.Model.UI.EgateMenuRevisionViewData>()
    .Columns(columns =>
        columns.Bound(c => c.ParentId)
            .Aggregate(a => a.Count()).ClientGroupHeaderTemplate(Html.ActionLink("Create a Revision for This Menu", "Edit", "Thing", new { menuid = "<#= Key #>" }, null).ToString());
        columns.Bound(c => c.ParentName);
        columns.Bound(c => c.ThingName);


    .Groupable(grouping => grouping.Groups(groups => { 
        groups.Add(c => c.EgateMenu.EgateMenuId);

This works. But it gives me:

Create a revision for this menu
1          Parent 1     Thing 1.1
1          Parent 1     Thing 1.2
1          Parent 1     Thing 1.3
Create a revision for this menu
2          Parent 2     Thing 2.1
2          Parent 2     Thing 2.2
2          Parent 2     Thing 2.3

And while that works, I'd much rather something more intuitive like:

Create a thing for parent 1
Thing 1.1
Thing 1.2
Thing 1.3
Create a thing for parent 2
Thing 2.1
Thing 2.2
Thing 2.3

Problem 1: Create a thing for... needs to pass the ParentId to the actionlink but it needs to display the ParentName for the client yet only one exists in the aggregate at a time.

Problem 2: I want to group by the Id without displaying the Id column in the results. But setting the column to visible(false) supresses the clientgroupheadertemplate.

preguntado el 08 de noviembre de 11 a las 16:11

3 Respuestas

Have you tried hiding the unwanted columns?

@( Html.Telerik().Grid<eGate.BackOffice.Core.Model.UI.EgateMenuRevisionViewData>()
.Columns(columns =>
    columns.Bound(c => c.ParentId).Visible(false);
        .Aggregate(a => a.Count()).ClientGroupHeaderTemplate(Html.ActionLink("Create a Revision for This Menu", "Edit", "Thing", new { menuid = "<#= Key #>" }, null).ToString());
    columns.Bound(c => c.ParentName).Visible(false);
    columns.Bound(c => c.ThingName);


Respondido el 24 de diciembre de 11 a las 06:12

Adición Visible(false) to the column binding suppresses the whole column itself from even being rendered in the client html - hence the suppression of the ClientGroupHeaderTemplate.

I would either try adding ParentId as a data key - e.g.

.DataKeys(keys =>
     keys.Add(k => k.ParentId);

I think this would only help if you were using the built in grid (AJAX or Server) DataBinding though (for Insert at least). With an ActionLink however... I don't have much experience with using mvc html helpers in client templates - but if you said the orignal example worked with it, shouldn't something like this work as well?

columns.Bound(c => c.ParentId).ClientTemplate("")
        .Aggregate(a => a.Count()).ClientGroupHeaderTemplate(Html.ActionLink("Create a thing for \"<#= ParentName #>\"", "Edit", "Thing", new { menuid = "<#= Key #>" }, null).ToString());

I added a blank ClientTemplate, which I assume would work so that the ID is not displayed.

Respondido el 27 de diciembre de 11 a las 23:12

According telerik : You can specify now Aggregate property with following values: Sum, Min, Max, Last, First, Count, Avg & Custom for every GridBoundColumn and the grid will calculate these aggregates if ShowFooter is set to true. In case of Custom aggregate the grid will raise event OnCustomAggregate where you can set desired result using e.Result.

So try First, Last or Custom options for every GridBoundColumn and set ShowFooter property to false.

<telerik:GridBoundColumn Aggregate="First" DataField="CustomerID" DataType="System.String" 
  HeaderText="CustomerID" SortExpression="CustomerID" UniqueName="CustomerID"> 

Respondido el 28 de diciembre de 11 a las 12:12

-1 because this is Telerik ASP.NET MVC related question, not Telerik ASP.NET Ajax - Levitikon

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.