Hello everyone, this is my first implementation of a Radzen component. I have a Radzen component that is not showing anything. I have included a div with a foreach loop that iterates through all the elements of the component and this does show the data, so the problem is obviously in the configuration of the component. Can anyone tell me what I am doing wrong?
@page "/pnd"
@using Sigea.Modelo.Models;
@inject IAsistenciaSigeaService asistenciaService
@inject IPNDService PNDService
@using System.Collections.ObjectModel;
<h1>Personal no docente</h1>
<RadzenGrid TItem="PND_HORAS" Data="@listaPndHoras">
<RadzenGridColumn TItem="PND_HORAS" Title="Nombre">
<Template Context="pndHoras">
@pndHoras.Personal.Nombre
</Template>
</RadzenGridColumn>
<RadzenGridColumn TItem="PND_HORAS" Title="Días trabajados">
<Template Context="pndHoras">
@pndHoras.DiasTrabajados
</Template>
</RadzenGridColumn>
<RadzenGridColumn TItem="PND_HORAS" Title="Horas trabajadas">
<Template Context="pndHoras">
@pndHoras.HorasTrabajadas
</Template>
</RadzenGridColumn>
</RadzenGrid>
<div>
<p>
@{
foreach (PND_HORAS item in listaPndHoras)
{
<a>Nombre: @item.Personal.Nombre</a>
}
}
</p>
</div>
@code {
List<PersonalNoDocente> personalNoDocentes;
ObservableCollection<PND_HORAS> listaPndHoras = new ObservableCollection<PND_HORAS>();
protected override async Task OnInitializedAsync()
{
// Obtener los datos de la entidad PersonalNoDocente
personalNoDocentes = await PNDService.TraerLista();
foreach (var pnd in personalNoDocentes)
{
var diasTrabajados = await asistenciaService.CalcularDiasTrabajadosAsync(pnd.Id, DateTime.Now.Month, DateTime.Now.Year);
var horasTrabajadas = await asistenciaService.CalcularHorasTrabajadasAsync(pnd.Id, DateTime.Now.Month, DateTime.Now.Year);
var saldoHorario = asistenciaService.CalcularDiferenciaHoras(horasTrabajadas, diasTrabajados);
var pndHoras = new PND_HORAS
{
Personal = pnd,
DiasTrabajados = diasTrabajados,
HorasTrabajadas = horasTrabajadas,
SaldoHorario = saldoHorario
};
listaPndHoras.Add(pndHoras);
StateHasChanged();
}
}
public class PND_HORAS
{
public PersonalNoDocente Personal { get; set; }
public int DiasTrabajados { get; set; }
public TimeSpan HorasTrabajadas { get; set; }
public TimeSpan SaldoHorario { get; set; }
}
}
IMHO you should direct assign new instance to the collection bound to the DataGrid Data property. Nothing will notify the DataGrid that you are adding items to the collection.
Adding items to ObservableCollection<T> after the DataGrid is bound will not have the expected result since our DataGrid will not listen to INotifyCollectionChanged.CollectionChanged.
This expression will be evaluated on every state change of the page and that's why it works. It creates also new instance each time and assigns Data. Assigning Data is the only way to show anything in our DataGrid.
Hello everyone, sorry for answering just now, on Friday I finished my workday and I no longer had access to my computer. I'm sorry to inform you that I made the changes and still nothing appears. This time, I manage to see for a second a legend that says "no record to display"
Strange.. but I have a couple of other suggestions you could try.
Try calling the Reload() method on the RadzenGrid component after the data is loaded.
Swap RadzenGrid with RadzenDataGrid.
To be frank I'm pretty new to Radzen and I'm not sure what the difference between RadzenGrid and RadzenDataGrid is. They seem to be doing the same kind of thing but RadzenDataGrid seems more potent and I can't find much about RadzenGrid in the documentation outside of GitHub. All examples and whatnot seem to use RadzenDataGrid.
Perhaps @enchev can shed some light on why there are two seemingly similar components?
Radzen.Blazor components check if the value of their Data property has changed. This requires the instance of listaPndHoras2 to actually change which is what listaPndHoras.ToList() does. Otherwise the value remains the same and calling Reload() would be needed.
RadzenGrid is the older version and we consider it obsolete. RadzenDataGrid is the newer version that we actively maintain. However both RadzenGrid and RadzenDataGrid behave the same when it comes to handing Data changes.
Here is another example:
<RadzenDataGrid Data=@data>
@code {
private List<DataItem> data = new List<DataItem>();
protected override async Task OnInitializedAsync()
{
data.Add(new DataItem()); // Won't will be displayed as data remains the same instance
}
}
<RadzenDataGrid Data=@data>
@code {
private List<DataItem> data = new List<DataItem>();
protected override async Task OnInitializedAsync()
{
data = new List<DataItem> { new DataItem() }; // Will display as data changes to a new instance
}
}
Hello, I still have the same result.
How can I know if the Radzen component is well registered? Is there a way to simulate some data to know if it appears?
PS: I had already changed to radzenDataGrid
Why have my post been closed? I still haven't solved the problem.