2011-11-08 30 views
2

我的網格:如何在Telerik MVC Grid聚合頭中顯示非聚合模型值?

@(Html.Telerik().Grid<eGate.BackOffice.Core.Model.UI.EgateMenuRevisionViewData>() 
     .Name("Grid") 
    .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); 
    }).Visible(false)) 

這工作。但它給了我:

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 

雖然這樣的作品,我寧願東西更直觀,如:

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 

問題1: 創建的事情...需要通過的ParentId到動作鏈接,但它需要顯示客戶端的ParentName,但一次只有一個存在於聚合中。

問題2: 我想通過Id進行分組而不顯示結果中的Id列。但將該列設置爲可見(false)會抑制clientgroupheadertemplate。

回答

0

添加Visible(false)到列綁定抑制自身在客戶端的HTML甚至被渲染整個列 - 在ClientGroupHeaderTemplate的,因此抑制。

我會嘗試添加ParentId作爲數據密鑰 - 例如,

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

我想,如果你使用內置的網格(AJAX或服務器)數據綁定,雖然這隻能幫助(用於插入至少)。然而,使用ActionLink ...我在客戶端模板中使用mvc html助手的經驗並不多 - 但是如果您說這個orignal示例使用了它,不應該像這樣工作嗎?

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

我添加了一個空白的ClientTemplate,我認爲這將工作,以便該ID不顯示。

0

你試過隱藏不需要的列嗎?

@(Html.Telerik().Grid<eGate.BackOffice.Core.Model.UI.EgateMenuRevisionViewData>() 
    .Name("Grid") 
.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); 

}) 
-1

根據Telerik的: 您現在可以使用下列值合計屬性:和,最小值,最大值,上次,首先,計數,平均&自定義爲每GridBoundColumn如果ShowFooter設置爲true,網格將計算這些聚集。在自定義聚合的情況下,網格會引發事件OnCustomAggregate,您可以在其中使用e.Result設置所需的結果。

因此,請爲每個GridBoundColumn嘗試First,Last或Custom選項,並將ShowFooter屬性設置爲false。

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

-1因爲這是Telerik ASP.NET MVC的相關問題,而不是Telerik ASP.NET Ajax – Levitikon