datagrid column sort direction #7370
-
I have created my own custom IComparer class and as part of the custom sorting, I need to pass the columns current SortDirection. as you can see below. I have worked around, by storing my own sort direction. but it's prone to getting out of sync with the true sort direction. is there anyway to safely get the columns actually current sort direction? <MudBlazor.PropertyColumn Property="x => x.ChassisNumber" Title="@ChassisColName" Comparer=" new DgvItemComparer(GetOrSetSortDirection(ChassisColName))" />
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
First you need to add a ref to the datagrid private SortDirection GetColumnSortDirection(string columnName)
{
if (columnName == null)
{
return SortDirection.None;
}
var ok = _dataGrid.SortDefinitions.TryGetValue(columnName, out var sortDefinition);
if (ok)
{
return sortDefinition.Descending ? SortDirection.Descending : SortDirection.Ascending;
}
return SortDirection.None;
} It's what datagrid using internally. |
Beta Was this translation helpful? Give feedback.
First you need to add a ref to the datagrid
MudDataGrid @ref="_dataGrid"
private MudDataGrid<YourType> _dataGrid = null!;
then you can use this method to extract the sort direction by column name:
It's what datagrid using internally.