Hi,
I have a RadzenDataGrid with a list of ItemTask with a property FamilyMember
Problem I can't display any information on the TItem property AssignTo witch is a objects
I create a simple example of Todo with two simple class model TaskItemDto and FamilyMemberDto.
I create these Item witch end with DTO to get EF out the way as now is just plain C# class instantiate in the OnInitializedAsync().
**My Environement **
-> Dotnet 9
-> Radzen component Version 5.9.8
-> Radzen studio 1.37.0
My Page Code
@page "/buggy-task"
@using FamilyPlanner.Models
@attribute [Authorize]
@inject IJSRuntime JSRuntime
@inject NavigationManager NavigationManager
@inject DialogService DialogService
@inject ContextMenuService ContextMenuService
@inject TooltipService TooltipService
@inject NotificationService NotificationService
<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End" Style="padding: 5px">
<RadzenButton Click=@(args => OnClick("Add Task")) Text="Ajouter" ButtonStyle="ButtonStyle.Primary" />
</RadzenStack>
<RadzenDataGrid AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.Advanced" AllowSorting="true"
PageSize="15" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
Data="@taskItemsDto" ColumnWidth="200px" LogicalFilterOperator="LogicalFilterOperator.Or"
SelectionMode="DataGridSelectionMode.Single" TItem="TaskItemDto">
<Columns>
<RadzenDataGridColumn Property="@nameof(TaskItemDto.Id)" Filterable="false" Title="ID" Frozen="true" Width="80px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn Property="@nameof(TaskItemDto.IsCompleted)" Title="Completed" Width="120px" />
<RadzenDataGridColumn Property="@nameof(TaskItemDto.Description)" Title="Description" Width="200px" />
<RadzenDataGridColumn Property="@nameof(TaskItemDto.DueDate)" Title="Due Date" FormatString="{0:MM/dd/yyyy}" Width="160px" />
<RadzenDataGridColumn Property="@nameof(TaskItemDto.AssignedTo.Name)" Title="Assigned To" Width="200px" />
</Columns>
</RadzenDataGrid>
@code {
protected List<TaskItemDto> taskItemsDto = new List<TaskItemDto>();
protected override async Task OnInitializedAsync()
{
// add data to the list taskItemDto
FamilyMemberDto daddy = new FamilyMemberDto()
{
Id = 1,
Name = "Daddy",
Role = "Parent"
};
FamilyMemberDto mommy = new FamilyMemberDto()
{
Id = 2,
Name = "Mommy",
Role = "Parent",
};
FamilyMemberDto damKid = new FamilyMemberDto()
{
Id = 3,
Name = "Juilette",
Role = "Children",
};
taskItemsDto.Add(new TaskItemDto()
{
Id = 1,
Description = "Shovel the snow out the driveway",
DueDate = DateTime.Now,
IsCompleted = false,
AssignedTo = daddy,
});
taskItemsDto.Add(new TaskItemDto()
{
Id = 2,
Description = "Check if daddy has been remove the snow",
DueDate = DateTime.Now,
IsCompleted = false,
AssignedToId = 2,
AssignedTo = mommy,
});
taskItemsDto.Add(new TaskItemDto()
{
Id = 3,
Description = "Not lissening at all",
DueDate = DateTime.Now,
IsCompleted = true,
AssignedTo = damKid,
});
}
private async Task OnClick(string text)
{
// Logique pour ajouter une nouvelle t che
NotificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Info, Summary = text, Detail = text, Duration = 4000 });
}
}
Problem is last column displying AssignTo.Name display.
the class name instead of the Value ex: Daddy, Mommy or kid.
Here the RadzenDataGrid Setup:
and the result is:
The TItem is configured and work for all others fields.
I can make it work by creating a getter on new Property MemberName retreiving info in the child object Member.
1-> Change the Class TaskItemDto
public class TaskItemDto
{
public int Id { get; set; }
public string Description { get; set; }
public DateTime DueDate { get; set; }
public bool IsCompleted { get; set; }
public int AssignedToId { get; set; }
public FamilyMemberDto AssignedTo { get; set; }
public string MemberName
{
get
{
return AssignedTo.Name;
}
}
}
2-> Change the Column in the RadzenDataGrid
<RadzenDataGridColumn Property="@nameof(TaskItemDto.MemberName)" Title="Assigned To" Width="200px" />
It display the info properly with the getter like (Daddy, mommy, etc)
I would like to display data directly without having to do a getter.
Like: TaskItem.AssignTo.Name
Any idea is this the correct Behavior or I misunderstand how to use it.
Thanks