Replies: 1 comment 1 reply
-
Maybe something like this will work. <FluentDataGrid Items="DataItems.AsQueryable()">
<PropertyColumn Property="@(item => item.Description)" Title="Description" Sortable="true" />
<!-- Display the number as a string but sort by the numeric value -->
<TemplateColumn SortBy="GridSort<MyItem>.ByAscending(item => item.Number)" Title="Number (String)">
@context.NumberString
</TemplateColumn>
<!-- Direct numeric column -->
<PropertyColumn Property="@(item => item.Number)" Title="Number (Numeric)" Sortable="true" />
</FluentDataGrid>
@code {
private List<MyItem> DataItems = new()
{
new MyItem { Description = "Row 1", Number = 10 },
new MyItem { Description = "Row 2", Number = 5.5 },
new MyItem { Description = "Row 3", Number = 444.7 },
new MyItem { Description = "Row 4", Number = 100 },
new MyItem { Description = "Row 5", Number = 2 }
};
public class MyItem
{
public double Number { get; set; }
public string NumberString => Number.ToString();
public string Description { get; set; } = "";
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Has anyone worked out how to use a natural sort on a datagrid column ?
We format figures as strings to make them more easily readable for users however the downside is that the default sort then treats the datagrid column as a string, sorting the figures incorrectly (for numerics that is)
Failing that , an alternate way to format columns in datagrid so it displays numbers with commas would work !
Beta Was this translation helpful? Give feedback.
All reactions