Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HeaderCellAsButtonWithMenu and ColumnOptions set but no sorting results in no menu shown #3309

Closed
davhdavh opened this issue Feb 6, 2025 · 3 comments · Fixed by #3310
Labels
closed:done Work is finished

Comments

@davhdavh
Copy link

davhdavh commented Feb 6, 2025

🐛 Bug Report

if ((Sortable is true || IsDefaultSortColumn) && (Grid.ResizableColumns || ColumnOptions is not null))
{
_isMenuOpen = !_isMenuOpen;
}
does not call StateHasChanged and thus the menu is never shown.

💻 Repro or Code Sample

<FluentDataGrid RowStyle="@(x => $"height:{(int)DataGridRowSize.Medium}px;")"
                HeaderCellAsButtonWithMenu="true"
                ResizableColumns="true"
                ResizeType="DataGridResizeType.Discrete"
>
    <TemplateColumn TGridItem="TGridItem" Sortable="false" Title="Actions" Align="@Align.End" Width="120px" Filtered="true">
     <ChildContent>
      Hello world
   </ChildContent>
     <ColumnOptions>Column Options</ColumnOptions>
    </TemplateColumn>
</FluentDataGrid>

🤔 Expected Behavior

clicking on TemplateColumn header shows Column Options and resize.

😯 Current Behavior

Nothing happens on click

💁 Possible Solution

Call StateHasChanged after changing property.

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Feb 6, 2025
vnbaaij added a commit that referenced this issue Feb 6, 2025
- Fix #3306 by accounting for Sortable being null
- Fix #3309 by adding a StateHasChanged
@vnbaaij vnbaaij added closed:done Work is finished and removed triage New issue. Needs to be looked at labels Feb 6, 2025
@vnbaaij
Copy link
Collaborator

vnbaaij commented Feb 6, 2025

Fix with PR mentioned

@vnbaaij vnbaaij closed this as completed Feb 6, 2025
@davhdavh
Copy link
Author

davhdavh commented Feb 7, 2025

On further investigation, this is not the correct fix for this bug.

There are 4 render states for menu:

  • has sort -> Grid.SortByColumnAsync
  • has resize -> Grid.ShowColumnResizeAsync
  • has column options -> Grid.ShowColumnOptionsAsync
  • has multiple -> _isMenuOpen = !_isMenuOpen
    private async Task HandleColumnHeaderClickedAsync()
    {
        if ((Sortable is true || IsDefaultSortColumn) && (Grid.ResizableColumns || ColumnOptions is not null))
        {
            _isMenuOpen = !_isMenuOpen;
        }
        else if ((Sortable is true || IsDefaultSortColumn) && !Grid.ResizableColumns && ColumnOptions is null)
        {
            await Grid.SortByColumnAsync(this);
        }
        else if (Sortable is not true && !IsDefaultSortColumn && ColumnOptions is null && Grid.ResizableColumns)
        {
            await Grid.ShowColumnResizeAsync(this);
        }
  }

-->

 private async Task HandleColumnHeaderClickedAsync()
 {
    var hasSorting = Sortable is true || IsDefaultSortColumn;
    var hasResize  = Grid.ResizableColumns;
    var hasOptions = ColumnOptions is not null;
    var hasMulti   = (hasSorting && hasResize) || (hasSorting && hasOptions) || (hasResize && hasOptions);
    if (hasMulti) { _isMenuOpen = !_isMenuOpen; }
    else if (hasSorting) { await Grid.SortByColumnAsync(this); }
    else if (hasResize) { await Grid.ShowColumnResizeAsync(this); }
    else if (hasOptions) { await Grid.ShowColumnOptionsAsync(this); }
 }

@vnbaaij
Copy link
Collaborator

vnbaaij commented Feb 7, 2025

That looks much clearer! Although our style rules will trigger on your formatting 😜

I'll amend the PR.

PR was mergedalready. I'll create a new one.

dvoituron pushed a commit that referenced this issue Feb 7, 2025
…3310)

* - Do not add global.json to repo
- Fix #3306 by accounting for Sortable being null
- Fix #3309 by adding a StateHasChanged

* - Cleanup issueTester
- Tune column/style behavior
- Fix tests
vnbaaij added a commit that referenced this issue Feb 7, 2025
* - Do not add global.json to repo
- Fix #3306 by accounting for Sortable being null
- Fix #3309 by adding a StateHasChanged

* - Cleanup issueTester
- Tune column/style behavior
- Fix tests

* - Refactor code that determines if column menu needs to be shown
- Refactor code that determines if header gets display:flex
- Do not show filter icon when using 'clasic' filter option button
- Fix more edge cases in displaying headers

* Cleanup IssueTester

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:done Work is finished
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants