Closed hereiznoy closed 1 year ago
I'm afraid that I'm unable to reproduce such problem on our demo: https://blazor.radzen.com/datagrid-loaddata
@enchev In your example, did you set the SortProperty
property of RadzenDataGridColumn
? It doesn't look like it, but I can't tell for sure from your screenshot. But it's the combination of that property plus the SortOrder
that I'm seeing an issue with. I can reproduce this in a very basic example (see below) with no dependencies other than the Radzen data grid stuff.
Perhaps I'm using SortProperty
incorrectly. What I want is to sort a given grid column by a value other than the one being displayed. Which works fine except on initial load.
Example (I believe this should initially order second record (with NameSortValue = x
first, but it does not)) :
<RadzenDataGrid
TItem="Thing"
Data="_things"
AllowSorting="true">
<Columns>
<RadzenDataGridColumn
TItem="Thing"
Property="Id"
Title="Id">
</RadzenDataGridColumn>
<RadzenDataGridColumn
TItem="Thing"
Property="Name"
Title="Name"
SortProperty="NameSortValue"
SortOrder="SortOrder.Ascending">
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
@code {
public class Thing
{
public int Id { get; set; }
public string Name { get; set; }
public string NameSortValue { get; set; }
}
private readonly IEnumerable<Thing> _things = new[]
{
new Thing {Id = 1, Name = "Bart", NameSortValue = "y"},
new Thing {Id = 2, Name = "Jason", NameSortValue = "x"}
};
}
When setting both the
SortOrder
andSortProperty
properties of aRadzenDataGridColumn
, on initial load the grid is not sorted by this column. However subsequent order operations (by clicking the sorting button on the column's UI) correctly orders records ascending and descending by that column. Also, removing theSortProperty
from the column declaration results in correct application of sort behavior on grid load (although in my case it's now ordering by the incorrect value).I've noticed by inspecting the
LoadDataArgs
object in the grid'sLoadData
event that on initial load theLoadDataArgs.OrderBy
property is empty.Example (SortValue is a property on the ActivityViewModel but is not a column displayed in the grid):