Here is my code below to reproduce - very simplified version of this one - DataGrid with custom sample of very simplified data, but without autosaving settings (only on demand through hitting the button) and serializing them.
Steps to reproduce - watch the parameter "args" of the LoadData method:
- Run the code
- Sort the list by Val2 - args.OrderBy: "Val2 asc"
- Save settings (hit the "SaveSettings" button) - args.OrderBy: "Val2 asc"
- Sort list by Val1 - args.OrderBy: "Val1 asc"
- Load settings saved before (hit the "LoadSettings" button) - args.OrderBy: "Val1 desc,Val2 asc" but must be "Val2 asc"
Interestingly, that Val1 sorting changed its value from "asc" to "desc" by itself - there are no steps in my actions where I set any sortings to "decs".
@using Radzen
@using System.Linq.Dynamic.Core
@page "/"
<RadzenButton Click="@Save" Text="SaveSettings" />
<RadzenButton Click="@Load" Text="LoadSettings" />
<RadzenDataGrid @bind-Settings="@Settings"
AllowSorting="true"
Data="@employees"
TItem="Employee"
Count="@count"
LoadData="@LoadData"
Style="height:400px">
<Columns>
<RadzenDataGridColumn TItem="Employee" Property="Val1" Title="Val1" />
<RadzenDataGridColumn TItem="Employee" Property="Val2" Title="Val2" />
</Columns>
</RadzenDataGrid>
@code {
public class Employee
{
public int Val1 { get; set; }
public int Val2 { get; set; }
}
List<Employee> source;
IEnumerable<Employee> employees;
int count;
DataGridSettings settings;
public DataGridSettings Settings
{
get => settings;
set
{
if (settings != value)
settings = value;
}
}
DataGridSettings cachedSettings;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
source = new List<Employee>()
{
new Employee() { Val1 = 0, Val2 = 20 },
new Employee() { Val1 = 1, Val2 = 10 },
new Employee() { Val1 = 2, Val2 = 50 },
new Employee() { Val1 = 3, Val2 = 80 },
new Employee() { Val1 = 4, Val2 = 30 },
};
}
protected void LoadData(LoadDataArgs args)
{
var query = source.AsQueryable();
if (!string.IsNullOrEmpty(args.OrderBy))
query = query.OrderBy(args.OrderBy);
employees = query.ToList();
count = employees.Count();
}
async Task Save()
{
await Task.CompletedTask;
cachedSettings = Settings;
}
async Task Load()
{
await Task.CompletedTask;
Settings = cachedSettings;
}
}