Hello. I've been trying to get the RadzenDataGrid with virtualization on to work with the filter template but for some reason all of my visible results seem to be one behind. I've included code using a modified version of the Filter Template demo example. I have changed the text at the top to display the current count. The count is changing for the expected filtered items but not the grid display. I did try to simulate using the LoadData async as I am planning to use this with a REST API. What am I doing wrong?
@if (initialEmployees == null)
{
<p><em>Loading...</em></p>
}
else
{
<RadzenText TextStyle="TextStyle.H6" TagName="TagName.H2" class="my-4">Current Result Count: @count</RadzenText>
<RadzenDataGrid @ref="grid" LoadData="@LoadData" IsLoading=@isLoading Count="count" Style="height:400px"
Data=@employees FilterMode="FilterMode.Simple"
AllowFiltering="true" AllowPaging="false" AllowSorting="true"
TItem="Employee" ColumnWidth="200px" AllowVirtualization="true" >
<Columns>
<RadzenDataGridColumn TItem="Employee" Property="ID" Title="ID" />
<RadzenDataGridColumn TItem="Employee" Title="Customer" Property="CompanyName" Type="typeof(IEnumerable<string>)"
FilterValue="@selectedCompanyNames" FilterOperator="FilterOperator.Contains" LogicalFilterOperator="LogicalFilterOperator.Or">
<FilterTemplate>
<RadzenDropDown @bind-Value=@selectedCompanyNames Style="width:100%;"
Change=@OnSelectedCompanyNamesChange Data="@(companyNames)" AllowClear="true" Multiple="true" />
</FilterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Employee" Property="TitleOfCourtesy" Title="Title Of Courtesy" FilterValue="@currentTOC">
<FilterTemplate>
<RadzenDropDown @bind-Value="@currentTOC" TextProperty="Text" ValueProperty="Value" Style="width:100%;"
Change=@OnSelectedTOCChange
Data="@(Enum.GetValues(typeof(TitleOfCourtesy)).Cast<TitleOfCourtesy?>().Select(t => new { Text = $"{t}", Value = t == TitleOfCourtesy.All ? null : t }))" />
</FilterTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
}
@code {
RadzenDataGrid<Employee> grid;
TitleOfCourtesy? currentTOC;
IEnumerable<string> selectedCompanyNames;
List<string> companyNames = new List<string> {"Vins et alcools Chevalier", "Toms Spezialitäten", "Hanari Carnes", "Richter Supermarkt", "Wellington Importadora", "Centro comercial Moctezuma" };
public enum TitleOfCourtesy
{
Ms,
Mr,
All = -1
}
public class Employee
{
public int ID { get; set; }
public string CompanyName { get; set; }
public TitleOfCourtesy TitleOfCourtesy { get; set; }
}
void OnSelectedCompanyNamesChange(object value)
{
if (selectedCompanyNames != null && !selectedCompanyNames.Any())
{
selectedCompanyNames = null;
}
}
void OnSelectedTOCChange(object value)
{
if (currentTOC == TitleOfCourtesy.All)
{
currentTOC = null;
}
}
IEnumerable<Employee> employees;
IEnumerable<Employee> initialEmployees;
protected override void OnInitialized()
{
//randomize the data for more employee variations
var random = new Random();
initialEmployees = Enumerable.Range(0, 40).Select(i =>
new Employee
{
ID = i,
CompanyName = companyNames[random.Next(companyNames.Count)],
TitleOfCourtesy = random.NextDouble() >= 0.5 ? TitleOfCourtesy.Mr : TitleOfCourtesy.Ms
});
}
int count;
bool isLoading = false;
async Task LoadData(LoadDataArgs args)
{
isLoading = true;
await Task.Yield();
var query = initialEmployees.AsQueryable();
if (!string.IsNullOrEmpty(args.Filter))
{
query = query.Where(args.Filter);
}
if (!string.IsNullOrEmpty(args.OrderBy))
{
query = query.OrderBy(args.OrderBy);
}
count = query.Count();
employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
isLoading = false;
}
}