How to create a master/detail relationship with Telerik and OData?
I have an OData WCF ADO.NET service created with Entity Framework using protocol version 2. The entity model looks like this:
I now wish to consume this using a Telerik RadGrid. Here's the markup so far:
<telerik:RadGrid ID="radGrid" runat="server" AutoGenerateColumns="false" Width="100%" Skin="Sitefinity">
<ClientSettings>
<DataBinding Location="http://aadev:8081/measuredata.svc">
<DataService TableName="MeasureTopics"></DataService>
</DataBinding>
</ClientSettings>
<MasterTableView DataKeyNames="MeasureTopicGuid" GroupLoadMode="Client" Name="MeasureTopics">
<Columns>
<telerik:GridBoundColumn DataField="TopicName" />
</Columns>
<DetailTables>
<telerik:GridTableView DataKeyNames="MeasureGuid" runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="TopicID" MasterKeyField="MeasureTopicGuid" />
</ParentTableRelation>
<Columns>
<tele开发者_开发技巧rik:GridBoundColumn DataField="MeasureKeyCode" />
<telerik:GridBoundColumn DataField="MeasureName" />
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
This shows measure topics and a right-arrow to expand into measure definitions, but clicking the arrow does nothing. At least part of the problem is that ParentTableRelation
can't work as "TopicID" doesn't exist on the entity. (It's not there because having "MeasureTopic" as a navigation property prevents EF from allowing it to also exist on the entity as a scalar.)
What I'd like to know is, as the relationship is coming through the OData feed as a link...
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/MeasureTopic" type="application/atom+xml;type=entry" title="MeasureTopic" href="MeasureDefinitions(guid'96df6072-a8e4-e011-890d-000c29ba97e5')/MeasureTopic" />
<category term="HealthMeasuresModel.MeasureDefinition" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:MeasureGuid m:type="Edm.Guid">96df6072-a8e4-e011-890d-000c29ba97e5</d:MeasureGuid>
<d:MeasureKeyCode>ABC-001</d:MeasureKeyCode>
<d:MeasureName>ABC Register</d:MeasureName>
<d:MeasureDescription>Test</d:MeasureDescription>
</m:properties>
</content>
...how do I configure RadGrid to understand it?
Your markup is mostly correct, only GroupLoadMode
should be HierarchyLoadMode
instead. The former specifies loading of groups, the latter - of hierarchical detail tables.
You also need some javascript, more specifically two RadGrid client events - OnHierarchyExpanding
and OnCommand
. The approach is demonstrated in this Telerik Blog post.
精彩评论