Skip to content

MudDataGrid: Make grouping two-way bindable (#8159)#8160

Merged
henon merged 2 commits intoMudBlazor:devfrom
Gopichandar:fix/mudgrid-grouping-bindable
Feb 15, 2024
Merged

MudDataGrid: Make grouping two-way bindable (#8159)#8160
henon merged 2 commits intoMudBlazor:devfrom
Gopichandar:fix/mudgrid-grouping-bindable

Conversation

@Gopichandar
Copy link
Contributor

@Gopichandar Gopichandar commented Feb 11, 2024

MudDataGrid: grouping changed callback added for notification

Description

Fixes #8159

How Has This Been Tested?

visually

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added bug Unexpected behavior or functionality not working as intended PR: needs review labels Feb 11, 2024
@codecov
Copy link

codecov bot commented Feb 11, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e8b0760) 88.12% compared to head (2643a5c) 88.25%.

Files Patch % Lines
...MudBlazor/Components/DataGrid/MudDataGrid.razor.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8160      +/-   ##
==========================================
+ Coverage   88.12%   88.25%   +0.12%     
==========================================
  Files         394      394              
  Lines       11760    11743      -17     
  Branches     2384     2378       -6     
==========================================
  Hits        10364    10364              
+ Misses        871      854      -17     
  Partials      525      525              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ScarletKuro
Copy link
Member

Hello. Thanks for the PR. Can you add unit tests for this?
@tjscience please help to review this when you got time.

@henon
Copy link
Contributor

henon commented Feb 11, 2024

@peterthorpe81 this might be related to your PR #8041 but I am not sure. Can you take a quick look?

@Gopichandar
Copy link
Contributor Author

Hi @ScarletKuro , unit test added.

@ScarletKuro
Copy link
Member

ScarletKuro commented Feb 15, 2024

@henon should we just merge it without @tjscience consent? IIRC this was asked even in old datagrid to have the ability to toggle groupping on/off

@henon henon changed the title MudDataGrid: grouping changed callback added for notification (#8159) MudDataGrid: Make grouping two-way bindable (#8159) Feb 15, 2024
@henon
Copy link
Contributor

henon commented Feb 15, 2024

@tjscience FYI, this is a pretty simple PR, so we are confident in merging this w/o your review.

@Gopichandar Thanks for your contribution!

@henon henon merged commit b5f06e7 into MudBlazor:dev Feb 15, 2024
@peterthorpe81
Copy link
Contributor

@henon sorry I didn't respond sooner, I can see the PR is merged. Yes I think its related as this PR seems to have the same two-way binding bug as I created with Hidden parameter.

If you use the modified example below. Toggling the "Group Category" switch will do nothing as there is an internal bool grouping. Changing the grouping in grid will trigger the event and change the switch though.

If you removed the internal bool grouping and used the Grouping parameter direct for state that creates the same issues I am indicating in #8041 i.e. you can't modify grouping in grid if you put Grouping="true" or use an expression.

@using System.Net.Http.Json
@using MudBlazor.Examples.Data.Models
@inject HttpClient httpClient

<MudDataGrid T="Element" @ref="grid" Items="@_elements" DragDropColumnReordering="@_dragDropReorderingEnabled" ColumnsPanelReordering="@_columnsPanelReorderingEnabled"
             ColumnResizeMode="ResizeMode.Container" Hideable="@_hideable" Filterable="@_filterable" Groupable="@_groupable" FilterMode="@_filterMode" ShowMenuIcon="true">
    <Columns>
        <SelectColumn T="Element"/>
        <PropertyColumn Property="x => x.Number" Title="Nr" />
        <PropertyColumn Property="x => x.Sign" Hidden="true" DragAndDropEnabled="false" Groupable="false" Sortable="false" Filterable="false" />
        <PropertyColumn Property="x => x.Name" Title="Name" Hidden="false" DragAndDropEnabled="true" Groupable="true" Sortable="true" Filterable="true" />
        <PropertyColumn Property="x => x.Position" Filterable="false" Hideable="false" />
        <PropertyColumn Property="x => x.Molar" Title="Molar mass" Hideable="true" />
        <PropertyColumn Property="x => x.Group" Title="Category" @bind-Grouping="@_group" />
        <TemplateColumn Title="Template" />
    </Columns>
    <PagerContent>
        <MudDataGridPager T="Element" />
    </PagerContent>
</MudDataGrid>

<div class="d-flex flex-rows flex-wrap mr-4">
    <MudSwitch @bind-Checked="@_dragDropReorderingEnabled" Color="Color.Primary">Drag Drop Column Reordering</MudSwitch>
    <MudSwitch @bind-Checked="@_columnsPanelReorderingEnabled" Color="Color.Primary">Columns Panel Column Reordering</MudSwitch>
    <MudSwitch @bind-Checked="@_hideable" Color="Color.Primary">Hideable</MudSwitch>
    <MudSwitch @bind-Checked="@_filterable" Color="Color.Primary">Filterable</MudSwitch>
    <MudSwitch @bind-Checked="@_groupable" Color="Color.Primary">Groupable</MudSwitch>    
    <MudSwitch @bind-Checked="@_group" Color="Color.Primary">Group Category</MudSwitch>   
</div>

<div class="d-flex flex-wrap mt-4">
    <MudRadioGroup T="DataGridFilterMode" @bind-SelectedOption="@_filterMode">
        <MudRadio Dense="true" Option="@DataGridFilterMode.Simple" Color="Color.Primary">Simple</MudRadio>
        <MudRadio Dense="true" Option="@DataGridFilterMode.ColumnFilterMenu" Color="Color.Tertiary">Column Menu</MudRadio>
        <MudRadio Dense="true" Option="@DataGridFilterMode.ColumnFilterRow">Column Row</MudRadio>
    </MudRadioGroup>
</div>
@code {
    IEnumerable<Element> _elements = new List<Element>();

    DataGridFilterMode _filterMode = DataGridFilterMode.Simple;
    bool _dragDropReorderingEnabled = true;
    bool _columnsPanelReorderingEnabled = true;
    bool _hideable = true;
    bool _filterable = true;
    bool _groupable = true;
    bool _group = true;
    public MudDataGrid<Element> grid = null;

    protected override async Task OnInitializedAsync()
    {
        _elements = await httpClient.GetFromJsonAsync<List<Element>>("webapi/periodictable");
    }
}

@henon
Copy link
Contributor

henon commented Feb 21, 2024

Dang :(

biegehydra pushed a commit to biegehydra/MudBlazor that referenced this pull request Apr 26, 2024
…or#8160)

* MudDataGrid: grouping changed callback added fot notification

* MudDataGrid: unit test added for Grouping binding

---------

Co-authored-by: Gopichandar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudDataGrid - Grouping should be bindable

4 participants