Repository navigation
[Feature Request] - DataGrid - Add DefaultSortPriority on the columns #5497
Replies: 5 comments 11 replies
|
Vincent Baaij (@vnbaaij) , Denis Voituron (@dvoituron) - Thoughts on this? |
|
Yes, your explanation makes sense. I believe we can go ahead with the PR you already created. |
|
Do we need to add complexity to the columns when we can use Can you give a simple example of something that can't be done with I don't understand the difficulty you're referring to when using |
|
I asked Copilot to compare the two options: with and without this new feature. The live result is, of course, the same: peek_2.mp4So the question is (1) whether this is really necessary and (2) whether it's the best solution For example, we could consider a <FluentDataGrid TGridItem="Opportunity"
ItemsProvider="@LoadItemsAsync"
SortMode="DataGridSortMode.Multiple"
DefaultSort="@_defaultSort"> 👈
<PropertyColumn ColumnId="owner"
Title="Owner"
Property="@(o => o.Owner)"
Sortable="true" />
<PropertyColumn ColumnId="company"
Title="Company"
Property="@(o => o.Company)"
Sortable="true" />
<PropertyColumn Title="Amount"
Property="@(o => o.Amount)" />
</FluentDataGrid>
@code {
private readonly DataGridSortDefinition[] _defaultSort =
[
new("company", DataGridSortDirection.Ascending),
new("owner", DataGridSortDirection.Ascending),
];
}A grid-level The main advantage is that it expresses the complete default sort in one place. An ordered collection of column identifiers and sort directions would make both the sorting sequence and each column’s direction immediately visible. The collection order would define priority naturally, without additional numeric values. This approach also separates two independent concerns: how columns are displayed and how rows are initially sorted. For configurable or saved views, the application could provide the default sort alongside the view’s filters and column layout, rather than distributing sorting settings across column declarations. Using existing There are trade-offs. However, for the configurable-view scenario described in #5497, I would favor |
|
I agree that a single parameter would be a much better design. I did not consider proposing this because it would be a breaking change and I know that in the past that you have been very hesitant to introduce breaking changes. At the end of the day, it does not matter to me how this is accomplished, only that I can set a multi-column default sort that can be expressed before an initial query has been executed so that my server side query does not roundtrip twice on initial load. Let me know if this is the direction you want to take this and I can adjust my PR accordingly. |

Uh oh!
There was an error while loading. Please reload this page.
Consider a grid that should always open in a particular sort order. If you've worked with views in Dataverse / Dynamics 365, this will be familiar. A view of Opportunities might always sort by Company Name and then by Owner, whatever order those columns are displayed in.
Since multi-column sorting was merged in #5312, a grid can declare a sort like this. You mark each column with
IsDefaultSortColumnandInitialSortDirection, and the grid applies the sort before its first query. The catch is that the sort priority follows the order in which the columns are declared. If the view shows Owner before Company Name but needs to sort by Company Name first, the declared sort can't express that.The only option left is
SetSortAsync. It takes column references, which don't exist until the grid has rendered its columns, and the grid runs its first query as soon as those columns are collected. So the data is loaded once in declaration order and then loaded again in the order you actually wanted. With server-side sorting, as in my case, that's two round trips every time the grid opens.A view selector makes this more common. Users might choose between "My Opportunities", "All Opportunities" and "All Open Opportunities", each with its own columns, column order, filters and sort. In each of those views, the order the columns appear in and the order the data is sorted in are separate decisions. Tying one to the other doesn't hold up.
DefaultSortPriorityseparates the two. Columns keep their display order, each declared sort column gets its own priority, and the grid loads in the right order with a single query.A PR has already been created, reviewed, and is ready to merge that will remedy this: #5460
All reactions