Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

peterthorpe81
Copy link
Contributor

@peterthorpe81 peterthorpe81 commented Apr 24, 2025

Description

MudDataGrid provides a GroupTemplate on each column to control what information is presented when grouping by that column.

Its quite a common scenario to want to provide the same grouping information no matter which column is grouped. e.g. a count of the rows in the group or a percentage of the total rows. Providing the GroupTemplate on each column can be quite tedious for large grids.

This PR adds the GroupTemplate at grid level. Each column will use the most specific one in logical order:
GroupTemplate Specified In Column -> Group Template Specified in Grid -> Default Group Template

Example usage added to docs:

<MudDataGrid @ref="dataGrid" MultiSelection="true" Items="@Elements" Filterable="true"
    Hideable="true" Groupable="true" GroupExpanded="false" GroupClassFunc="GroupClassFunc">
    <ToolBarContent>
        <MudText Typo="Typo.h6">Periodic Elements</MudText>
        <MudSpacer />
    </ToolBarContent>
    <GroupTemplate>
        <span style="font-weight:bold">
            @context.DataGrid.GroupedColumn.Title: @context.Grouping.Key Count: @context.Grouping.Count()
            @if (context.DataGrid.FilteredItems.Count() != 0)
            {
                @string.Format(" Percentage: {0:P1}", context.Grouping.Count() / ((double)context.DataGrid.FilteredItems.Count()))
            }
            </span>
    </GroupTemplate>
    <Columns>
        <PropertyColumn Property="x => x.Number" Title="Nr" Filterable="false" Groupable="false" />
        <PropertyColumn Property="x => x.Sign" />
        <PropertyColumn Property="x => x.Name" />
        <PropertyColumn Property="x => x.Position" />
        <PropertyColumn Property="x => x.Molar" Title="Molar mass" />
        <PropertyColumn Property="x => x.Group" Title="Category" Grouping GroupBy="@_groupBy">
<!--overrides the grid level one -->
            <GroupTemplate>
                @if (_customizeGroupTemplate)
                {
                    <span style="font-weight:bold">Group: @context.Grouping.Key <MudChip Variant="Variant.Outlined" Color="Color.Primary" Size="Size.Small">total @context.Grouping.Count()</MudChip></span>
                }
                else
                {
                    <span style="font-weight:bold">Category: @context.Grouping.Key</span>
                }
            </GroupTemplate>
        </PropertyColumn>
    </Columns>
</MudDataGrid>

img

Note the PR makes the GroupedColumn property public and DataGrid accessible via GroupDefinition to allow for more complex aggregates. I think these are ok as DataGrid can be accessed by referencing anyway and GroupedColumn is only a getter.

How Has This Been Tested?

Visually. I'm not sure there are any tests to implement.

Type 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)
  • Documentation (fix or improvement to the website or code docs)

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 enhancement Request for adding a new feature or enhancing existing functionality (not fixing a defect) PR: needs review labels Apr 24, 2025
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.13%. Comparing base (9dc076c) to head (bcde2e4).
Report is 28 commits behind head on dev.

Files with missing lines Patch % Lines
...dBlazor/Components/DataGrid/DataGridGroupRow.razor 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #11237      +/-   ##
==========================================
+ Coverage   91.10%   91.13%   +0.02%     
==========================================
  Files         465      466       +1     
  Lines       14407    14417      +10     
  Branches     2788     2792       +4     
==========================================
+ Hits        13126    13139      +13     
+ Misses        642      641       -1     
+ Partials      639      637       -2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@versile2
Copy link
Contributor

There is a pending PR that is going to cause quite a bit of conflicts, but should help with better separation if you wish to redo it. As for tests you should be able to implement a simple test to show the default grouping is accepted, and then an override grouping is accepted over it.

#11083

@peterthorpe81
Copy link
Contributor Author

There is a pending PR that is going to cause quite a bit of conflicts, but should help with better separation if you wish to redo it. As for tests you should be able to implement a simple test to show the default grouping is accepted, and then an override grouping is accepted over it.

#11083

Looks good. I will tweak the PR once that's in dev.

@ScarletKuro
Copy link
Member

Looks good. I will tweak the PR once that's in dev.

It's in dev now.

@christophe-mommer
Copy link

I'm looking forward on this, would be very helpful in my scenario!

@versile2
Copy link
Contributor

versile2 commented May 5, 2025

There is a pending PR that is going to cause quite a bit of conflicts, but should help with better separation if you wish to redo it. As for tests you should be able to implement a simple test to show the default grouping is accepted, and then an override grouping is accepted over it.
#11083

Looks good. I will tweak the PR once that's in dev.

Are you still interested in this feature or should we close this to let someone else do it?

@peterthorpe81 peterthorpe81 force-pushed the feature/muddatagrid-default-grouping-template branch 4 times, most recently from e42cf7f to a442ca4 Compare May 6, 2025 14:19
@peterthorpe81
Copy link
Contributor Author

This should be updated to work with the multi level hierarchy.

I have added basic tests to check the group row content with and without a template set at grid level.

@peterthorpe81 peterthorpe81 force-pushed the feature/muddatagrid-default-grouping-template branch from a442ca4 to 7d63b58 Compare May 22, 2025 08:38
@versile2
Copy link
Contributor

So is this readu for review again?

@peterthorpe81
Copy link
Contributor Author

Yes ready for review.

Copy link

sonarqubecloud bot commented Jun 2, 2025

@peterthorpe81 peterthorpe81 requested a review from versile2 June 2, 2025 11:58
Copy link
Contributor

@versile2 versile2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScarletKuro This is ready for your review when time permits. I visually tested in both BSS and WASM as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for adding a new feature or enhancing existing functionality (not fixing a defect)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants