Hi,
First of all thanks for such a great set of components in Radzen and all the effort behind it, I really enjoy the work done here.
I wanted to ask regarding the RadzenDataGridColumn using OData with relationships.
The scenario presents an entity EntityA related to an entity EntityB with a n:n relationship. When applying a filter using RadezDropdown in RadzenDataGridColumn, the OData filter generated is not accepted by the OData endpoint.
OData Url generated: https://localhost/api/odata/EntityA?$filter=EntityB/Type+in+('TypeA'%2C'TypeB')
OData Url expected: https://localhost/api/odata/EntityA?$filter=EntityBs/any(entityB:+entityB/Type+in+('TypeAId'%2C'TypeBId'))) (or something equivalent)
Code:
<RadzenDataGrid @ref=radzenDataGrid
AllowFiltering=true
AllowPaging=true
AllowSorting=true
AllowColumnResize=true
Count=@entityAsCount
ColumnWidth="180px"
Data=@entityAs
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
FilterMode="FilterMode.Advanced"
FilterPopupRenderMode="PopupRenderMode.OnDemand"
IsLoading=@isLoading
KeyProperty=@nameof(EntityA.Id)
LoadData=@LoadData
PagerHorizontalAlign="HorizontalAlign.Center"
PageSize=PAGE_ITEMS
TItem=EntityA>
<Columns>
...
<RadzenDataGridColumn Property="EntityBs"
FilterProperty="EntityB/Type"
TItem=EntityA
Title="Entity Bs"
Type=@typeof(IEnumerable<EntityB>)
FilterValue=@selectedEntityBs
FilterOperator=FilterOperator.Contains
Sortable=false>
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedEntityBs
class="w-100"
Change=@OnSelectEntityB
Data=@entityBTypes <-- Enum values
TextProperty="Text"
ValueProperty="Value"
AllowClear=true
AllowSelectAll=false
Multiple=true />
</FilterTemplate>
<Template Context="entityA">
@entityA.EntityBsJoinedByCommaString
</Template>
</RadzenDataGridColumn>
...
@code {
[Inject]
private EntityARepository EntityARepository { get; set; } = default!;
public bool isLoading = true;
public int entityAsCount = default!;
public RadzenDataGrid<EntityA> radzenDataGrid = default!;
public IEnumerable<EntityA> entityAs = default!;
public IEnumerable<object> entityBsTypes = Enum.GetValues(typeof(EntityByTypes)).Cast<Enum>().Select(t => new { Text = t.ToString(), Value = t });
public IEnumerable<Enum> selectedEntityBs = default!;
async Task OnSelectEntityB(object value)
{
await radzenDataGrid.FirstPage();
}
async Task LoadData(LoadDataArgs args)
{
var result = await EntityARepository.Get(
count: true,
expand: @nameof(EntityA.EntityBs),
filter: args.Filter,
orderby: args.OrderBy,
select: $@"
{nameof(EntityA.Id)},
{nameof(EntityA.Description)},
{nameof(EntityA.CreatedDateTime)},
",
skip: args.Skip,
top: args.Top
);
entityAsCount = result.Count;
entityAs = result.Value.AsODataEnumerable();
isLoading = false;
}
}
EntityARepository.cs:
public async Task<ODataServiceResult<EntityA>> Get(
bool? count = default,
int? skip = default,
int? top = default,
string? expand = default,
string? filter = default,
string? orderby = default,
string? select = default
)
{
var uri = routeRepository.GetUri(entityARouteId);
var oDataUriRoute = uri.GetODataUri(
count: count,
expand: expand,
filter: filter,
orderby: orderby,
select: select,
skip: skip,
top: top
).ToString();
return await httpClient.GetFromJsonAsync<ODataServiceResult<EntityA>>(
oDataUriRoute,
jsonSerializerOptions
) ?? default!;
}
I'm trying to follow the Radzen components documentation examples, but I'm not able to make it work in such scenario.
Any idea will be more than welcome.
And again thanks to the team for such amazing components and community.
Javier
Context info:
<TargetFramework>net7.0</TargetFramework>
<PackageReference Include="BuildWebCompiler2022" Version="1.14.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Radzen.Blazor" Version="4.12.0" />