Initial Sort on RadzenDataGridColumn with SortProperty Set Not Working #681

Closed
opened 2026-01-29 17:41:31 +00:00 by claunia · 3 comments
Owner

Originally created by @hereiznoy on GitHub (Dec 13, 2022).

When setting both the SortOrder and SortProperty properties of a RadzenDataGridColumn, 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 the SortProperty 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's LoadData event that on initial load the LoadDataArgs.OrderBy property is empty.

Example (SortValue is a property on the ActivityViewModel but is not a column displayed in the grid):

<RadzenDataGridColumn
    TItem="ActivityViewModel"
    Property="GGRCNumber"
    Title="GGRC Number"
    SortOrder="SortOrder.Ascending"
    SortProperty="SortValue"
    Width="150px">
    ...
</RadzenDataGridColumn>

OS: Windows 10
Browser: Microsoft Edge v110.0.1543.0 dev
Originally created by @hereiznoy on GitHub (Dec 13, 2022). When setting both the `SortOrder` and `SortProperty` properties of a `RadzenDataGridColumn`, 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 the `SortProperty` 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's `LoadData` event that on initial load the `LoadDataArgs.OrderBy` property is empty. Example (_SortValue_ is a property on the **ActivityViewModel** but is not a column displayed in the grid): ``` <RadzenDataGridColumn TItem="ActivityViewModel" Property="GGRCNumber" Title="GGRC Number" SortOrder="SortOrder.Ascending" SortProperty="SortValue" Width="150px"> ... </RadzenDataGridColumn> OS: Windows 10 Browser: Microsoft Edge v110.0.1543.0 dev
Author
Owner

@enchev commented on GitHub (Dec 14, 2022):

I'm afraid that I'm unable to reproduce such problem on our demo:
https://blazor.radzen.com/datagrid-loaddata
image

@enchev commented on GitHub (Dec 14, 2022): I'm afraid that I'm unable to reproduce such problem on our demo: https://blazor.radzen.com/datagrid-loaddata ![image](https://user-images.githubusercontent.com/5804953/207532481-5beb48f6-301d-4e75-8feb-2faeefe3b1a1.png)
Author
Owner

@hereiznoy commented on GitHub (Dec 14, 2022):

@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"}
    };
}
@hereiznoy commented on GitHub (Dec 14, 2022): @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"} }; } ```
Author
Owner

@enchev commented on GitHub (Dec 16, 2022):

Fixed in 7aa37cd6cb

@enchev commented on GitHub (Dec 16, 2022): Fixed in https://github.com/radzenhq/radzen-blazor/commit/7aa37cd6cb2e5ddaf1876b82b09927f18a3794fe
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#681