Buenas, estoy usando un componente hijo que lo uso para mostrar una tabla pero dinamicamente, pasandole el modelo y los datos. Lo que pasa es que yo soy nuevo en Radzen y Blazor, al mostrar los datos en la tabla, uso el ciclo de vida OnParametersSetAsync para que cuando detecte que la peticion retorno los datos, el enseguida me actualice la variable dataTable y count, y me lo muestra, pero yo al filtrar no me filtra, como haria para que actualice los registros con los filtros?.
Aquí esta el componente hijo:
@typeparam TItem
@using System.Linq.Dynamic.Core
@using System.Reflection;
@using System.ComponentModel;
@using valoranz_frontend.Models
@page "/table"
<RadzenDataGrid EmptyText="No hay datos"
AllowFiltering="true"
IsLoading=@isLoading
AllowColumnResize="true"
AllowAlternatingRows="false"
FilterMode="FilterMode.Simple"
AllowSorting="true"
PageSize="10"
AllowPaging="true"
Count="@count"
PagerHorizontalAlign="HorizontalAlign.Center"
ShowPagingSummary="false"
Data="@dataTable"
TItem="TItem"
ColumnWidth="300px"
LoadData="@LoadData"
LogicalFilterOperator="LogicalFilterOperator.And"
@ref="grid">
<Columns>
@foreach (PropertyInfo propertyInfo in propertyInfos)
{
<RadzenDataGridColumn TItem="TItem"
Title="@(propertyInfo.GetCustomAttribute<DisplayNameAttribute>().DisplayName)"
Property="@(propertyInfo.Name)"
Width="160px" />
}
<RadzenDataGridColumn TItem="TItem" Title="DESCARGA">
<Template>
<RadzenButton Click="@(()=>ClickBoton.InvokeAsync("Esto viene desde el hijo"))" />
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
[Parameter]
public EventCallback<string> ClickBoton { get; set; }
[Parameter]
public IEnumerable<TItem> ExternalData { get; set; }
public IEnumerable<TItem> dataTable = new List<TItem>();
private IDictionary<string, string> dataDictionary;
private RadzenDataGrid<TItem> grid;
PropertyInfo[] propertyInfos;
bool isLoading = false;
int count;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
propertyInfos = typeof(TItem).GetProperties();
}
protected override async Task OnParametersSetAsync()
{
if (ExternalData != null && ExternalData.Any())
{
dataTable = ExternalData;
count = dataTable.Count();
}
await base.OnParametersSetAsync();
}
void LoadData(LoadDataArgs args)
{
//dataDictionary = new Dictionary<string, string>();
//foreach (var filter in args.Filters)
//{
// string property = filter.Property;
// string filterValue = filter.FilterValue.ToString();
// if (dataDictionary.ContainsKey(property))
// {
// dataDictionary[property] = filterValue;
// }
// else
// {
// if (!string.IsNullOrEmpty(filterValue))
// {
// dataDictionary.Add(property, filterValue);
// }
// }
//}
//foreach (var item in dataDictionary)
//{
// Console.WriteLine($"Propiedad: {item.Key}, Valor del filtro: {item.Value}");
//}
//Console.WriteLine("Registros en la tabla: " + grid.Count);
//Console.WriteLine("Registros en la tabla: " + grid.Filter);
}
public void clearFilters()
{
foreach(var col in grid.ColumnsCollection)
{
col.ClearFilters();
}
}
}