Hello Everyone,
I am trying to add a RadzenDataGrid to a Dialog. I set the Attribute AllowVirtualization="true". Everything seems fine until I add the code Debug.WriteLine("Top {0} Skip {1}", args.Top, args.Skip);
. I found that the message has been called at least twice, and more query called by calling dataGrid.Reload();
. It makes me confused.
When I set the Attribute AllowPaging="true", Everything is fine. The debug message only show once when initializing.
I have been tried to set the debug breakpoint to see what happened, but I can't see anything about the details of Radzen Components. I have read the source code about the RadzenDataGrid but I did't find any problems yet. Maybe I will try to figure out the details of process by reading the source code, but I hope someone can give me help to find out the deeper problem.
Sorry for my poor English, but I need the help. Thank you everyone.
Here is some code snippets:
<RadzenDataGrid TItem="TItem" AllowColumnResize AllowAlternatingRows AllowSorting AllowColumnReorder="false" ColumnReordered="OnColumnReordered" Style="flex: 1; height: 200px;"
ColumnWidth="200px" IsLoading="_loading" @ref="dataGrid" Data="_data" Count="_count" LoadData="LoadData" AllowVirtualization="true" RowDoubleClick="RowDoubleClick">
...Some config about columns
</RadzenDataGrid>
private async Task LoadData(LoadDataArgs args)
{
_loading = true;
Debug.WriteLine("Top {0} Skip {1}", args.Top, args.Skip);
Db.Ado.CancellationToken = token;
var exp = Expressionable.Create<Employee>();
exp.Or(e => e.Name.Contains(search))
.Or(e => e.SysNumber.Contains(search))
.Or(e => e.Name.Contains(search))
.Or(e => e.MnemonicCode.Contains(search));
var accId = await authService.GetAccountId();
if (DefaultValue > 0)
{
curParentId = await Db.Queryable<Employee>().Where(it => it.Id == DefaultValue).Select(it => it.ParentId).FirstAsync();
}
List<OrderByModel> orderByModels = new();
if (args.Sorts.Any())
{
foreach (var sort in args.Sorts)
{
var prop = typeof(Employee).GetProperty(sort.Property);
if (prop == null) continue;
if (!CheckAndGetFieldName(prop, out var fieldName)) continue;
orderByModels.Add(new() { FieldName = "e." + fieldName, OrderByType = sort.SortOrder == SortOrder.Descending ? OrderByType.Desc : OrderByType.Asc });
}
}
var query = Db.Queryable<Employee>();
if (IsOperator)
{
query = query.InnerJoin<Operator>((e, o) => e.Id == o.EmployeeId);
}
else if (!string.IsNullOrEmpty(search))
{
query = query.Where(e => !e.HasChildren);
}
else
{
query = query.Where(e => e.ParentId == curParentId);
}
query = query.Where(e => e.AccountId == accId).Where(exp.ToExpression()).OrderBy(orderByModels);
_count = await query.CountAsync();
if (args.Skip.HasValue)
query = query.Skip(args.Skip.Value);
if (args.Top.HasValue)
query = query.Take(args.Top.Value);
_data = await query.ToListAsync();
_loading=false;
}