This seemed to work in the past but for some reason, I may have made a change that broke it and can't figure out how to fix it. The issue I am having is when using the DataGrid with the filter set to SimpleWithMenu and using a dropdown with multiple set to true. See code below for more detail. When making a selection or checking the box on the dropdown it calls the load data method but does not update the viewers page. If a second checkbox is selected then the page updates. If the X is clicked to clear it also updates. However the problem I am having is that when the initial filter or a single filter is applied even though the data is filtered the page is not updated. I have tried StateHasChanged, grid.Reload and a couple other things but nothing seemed to work. If I change the Multiple to false it also filters the data but the page does not get updated. Not sure if this is related to switching to virtualization as it worked before and one of the several changes I made was to virtualize it. Here is the code.
@page "/TestSearch"
@inherits TestSearchBase
<div class="container-fluid">
<RadzenDataGrid @ref=@grid Data="@Models" TItem="SearchViewModel" LoadData="@LoadData" Count="@Count" AllowVirtualization="true"
AllowColumnResize="true" AllowAlternatingRows="true" AllowSorting="true" Style="height: 85vh;"
AllowFiltering="true" FilterMode="FilterMode.SimpleWithMenu"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" LogicalFilterOperator="LogicalFilterOperator.And">
<Columns>
<RadzenDataGridColumn TItem="SearchViewModel" Property="LastName" Title="Last Name" SortOrder="SortOrder.Ascending" />
<RadzenDataGridColumn TItem="SearchViewModel" Property="FirstName" Title="First Name" />
<RadzenDataGridColumn TItem="SearchViewModel" Title="Race" Property="Race.Name" Type="typeof(IEnumerable<string>)"
FilterValue="@selectedRace" LogicalFilterOperator="LogicalFilterOperator.Or">
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedRace Style="width:100%;" Data=@RaceList
AllowClear="true" Multiple="false" Change=@OnSelectedRaceChanged />
</FilterTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
</div>
Class behind page
public class TestSearchBase : ComponentBase
{
[Inject] private IPersonRepo PersonRepo { get; set; }
[Inject] public ILookUpGroupRepo LookUpGroupRepo { get; set; }
[Inject] public IMapper Mapper { get; set; }
public RadzenDataGrid<SearchViewModel> grid;
public ICollection<SearchViewModel> Models { get; set; } = null;
public string selectedRace { get; set; }
public List<string> RaceList { get; set; }
public int Count { get; set; }
protected override async Task OnInitializedAsync() => await LoadDDLs();
public void OnSelectedRaceChanged(object value)
{
if (selectedRace != null && selectedRace.Any() == false) { selectedRace = null; }
}
public void LoadData(LoadDataArgs args)
{
var people = PersonRepo.SearchList(args, out int count);
Count = count;
Models = Mapper.Map<List<SearchViewModel>>(people);
foreach (var model in Models)
{
model.FirstName = new Guid().ToString();
model.LastName = new Guid().ToString();
}
StateHasChanged();
}
private async Task LoadDDLs()
{
var raceGroup = await LookUpGroupRepo.GetByNameAsync("Race");
RaceList = raceGroup.LookUpItem.Select(s => s.Name).ToList();
RaceList.Insert(0, "Not specified");
}
}
Repo method including the applying of filter, sort, take and skip
public List<Search> SearchList(LoadDataArgs args, out int count)
{
count = 0;
using var context = _factory.CreateDbContext();
{
var people = context.Person.Include(i => i.Race).AsQueryable();
if (!string.IsNullOrEmpty(args.Filter))
{
people = people.Where(args.Filter);
}
if (!string.IsNullOrEmpty(args.OrderBy))
{
people = people.OrderBy(args.OrderBy);
}
count = people.Count();
return people.Skip(args.Skip.Value).Take(args.Top.Value)
.Select(s => new Search(s))
.ToList();
}
}
Any help is appreciated.