MudBlazor/MudBlazor

SortDefinitions parameter is ignored in MudDataGrid when SortMode is Single

Open

#9,021 opened on May 20, 2024

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (1,631 forks)batch import
buggood first issue

Repository metrics

Stars
 (10,394 stars)
PR merge metrics
 (Avg merge 6d 6h) (108 merged PRs in 30d)

Description

Bug type

Component

Component name

MudDataGrid

What happened?

Have a look at the reproduction link.

  • I want to set an initial sort definition via the SortDefinitions-parameter.
  • This only works if the SortMode-parameter is SortMode.Multiple.
  • If set to SortMode.Single, the initial definitions are cleared.

The bug is probably located in:

  • File MudDataGrid.razor.cs
  • Method SetParametersAsync
        [Parameter] public SortMode SortMode { get; set; } = SortMode.Multiple;

        // ...

        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var sortModeBefore = SortMode;
            await base.SetParametersAsync(parameters);

            if (parameters.TryGetValue(nameof(SortMode), out SortMode sortMode) && sortMode != sortModeBefore)
                await ClearCurrentSortings();
        }

Because the SortMode is initially Multiple, the definitions are cleared if the mode is set to Single. I dont know if the .Clear() makes sense at all. But it should be NOT cleared if the sort mode is set initially.

Expected behavior

Given SortDefinitions should be work in both SortModes Do not clear SortDefinitions initially.

Reproduction link

https://try.mudblazor.com/snippet/QYwIEJcYRvsikHZP

Reproduction steps

On MudDataGrid

  1. Set SortDefinitions
  2. Set SortMode to Single

Relevant log output

No response

Version (bug)

6.19.1

Version (working)

No response

What browsers are you seeing the problem on?

Chrome

On which operating systems are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project's Code of Conduct

Contributor guide