I have put an example where Field argument cannot fulfil what I need to do.
The Column names and Field names are only discovered at runtime.
I can get the values to be displayed as I want using the <Template> element/component however I cannot grouping or sorting on these columns.
<TelerikGrid Data="@simplePropertiescollection" Height="500px"
Sortable="true"
Groupable="true"
Resizable="true"
Reorderable="true">
<GridColumns>
<GridColumn Field="@(nameof(SimpleProperties.Name))" Title="Name" />
@foreach (string prop in PropColumns)
{
<GridColumn FieldFunc = "(v) =>v.GetProps(prop)" Title="@prop">
<Template>
@{
// FieldFunc would replace the code below
string text = (context as SimpleProperties)?.GetProp(prop);
}
@text
</Template>
</GridColumn>
}
</GridColumns>
</TelerikGrid>
@code
{
List<SimpleProperties> simplePropertiescollection = new List<SimpleProperties>();
List<string> PropColumns { get; set; } = new();
public class SimpleProperties
{
public string Name {get; set;}
public List<SimpleProperty?>? Properties { get; set; }
public string? GetProp(string name)
{
return Properties.FirstOrDefault((SimpleProperty o) => o?.Name == name)?.Value;
}
}
public class SimpleProperty
{
public string? Name { get; set; }
public string? Value { get; set; }
}
}