Skip to content

datagrid column sort direction #7370

Answered by ScarletKuro
RayNixon665 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

    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.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@RayNixon665
Comment options

@holm76
Comment options

@holm76
Comment options

@holm76
Comment options

Answer selected by RayNixon665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants