Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DataGrid Grouping to skip "null" group#11912

Unanswered
legrab asked this question inQ&A
Sep 25, 2025· 2 comments· 5 replies
Discussion options

When using the Grouping feature of MudDataGrid, I’d like to have a way for certain items to remain ungrouped.

In my dataset, each entry has a GroupIdentifier property. For some entries, this property is not set. The issue is that these entries are still placed into an empty group, rather than appearing outside of any group.

I’m not sure if I’ve missed an existing option for this, but I couldn’t find a way to let these items fall outside of grouping.

My current code:

 <PropertyColumn Property="x => x.GroupIdentifier"                            Title="@GlobalLocalizer[nameof(DbVariable.GroupIdentifier)]"                            Hidden="true" Grouping GroupBy="@(x => x.GroupIdentifier ?? string.Empty)"/>

Example: here, PanelId falls into the string.Empty group (ignore the nonsense labels in this test):
image

If I return null or omit custom GroupBy logic, it doesn’t throw (thanks tothis fix), but the result is worse because "null" is explicitly shown:
image

What I’d like to achieve:

  • These items should appear outside of grouping, on the same level as the other group labels.
  • Conceptually, it would be an “always open ungrouped group” with its header row hidden in the generated HTML.
  • Ideally, the ungrouped items would appear below the grouped ones, but above would also work.
    • Below the groups would require the header row to be visible for separation, but this separator row could be a non-interactive empty row.

Mockup of the desired outcome when no-group on top:
image

And when below:
image

Is this possible to achieve?
Would you see this as a valuable feature by a config attribute on the PropertyColumn as "skip groupingnull group"?

You must be logged in to vote

Replies: 2 comments 5 replies

Comment options

@versile2

You must be logged in to vote
0 replies
Comment options

Thank you for the suggestion. I believe it is a valid one, however the mass consensus was to create a null/empty GroupBy like you see in your samples. I do not think the complexity involved with allowing it to work both ways as a value proposition (opinion), however I do believe what you want is more possible than you think using Row Detail View (Hierarchy Columns). You would have to adjust your data to work with it but that would be minimal work and you can have each RowDetail have children as you wish (and create multiple groups within as you wish)

Any additional thoughts?

V

You must be logged in to vote
5 replies
@legrab
Comment options

I currently have a nested recursive component calledDbVariableGrid as follows, keeping minimal snippet:

<MudDataGrid ref="@DataGrid"             T="DbVariable"             Items="@Items"             Groupable="true" GroupExpanded="false">    <Columns>        <HierarchyColumn T="DbVariable"/>        <PropertyColumn Property="x => x.Name"/>            @if (Items.Count == 0 || Items.Any(i => i.GroupIdentifier != null))        {            <PropertyColumn Property="x => x.GroupIdentifier" Hidden="true"                                           Grouping GroupBy="@(x => x.GroupIdentifier ?? string.Empty)"/>        }    </Columns>    <ChildRowContent>        @if (context.Item.Items.Count > 0)        {            <DbVariableGrid Items="@context.Item.Items" />        }    </ChildRowContent></MudDataGrid>

Currently, I avoid the PropertyColumn, if no item has GroupIdentifier in the given depth and generate the next layer if there are more Items of an item of this layer.

using Row Detail View (Hierarchy Columns).
adjust your data
have each RowDetail have children and create multiple groups within

I'm not sure I get it right.
Are you suggesting to drop the basic Property-based grouping and implement the DataGrid against some List<Group> instead of the List itself? Then another List within the ChildRowContent?

So basically something like this?

<MudDataGrid T="Group<DbVariable>" Items="@GetGroupedList(Items)">    <Columns>        <HierarchyColumn T="Group<DbVariable>" />        <PropertyColumn Title="Group" Property="g => g.Key" />    </Columns>    <ChildRowContent>        <MudDataGrid T="DbVariable" Items="@context.Item.Items" Groupable="false">            <Columns>                <HierarchyColumn T="TItem" />                <PropertyColumn Property="x => x.Name" />                <PropertyColumn Property="x => x.GroupIdentifier" Hidden="true"                                              Grouping GroupBy="@(x => x.GroupIdentifier ?? string.Empty)"/>            </Columns>            <ChildRowContent>                @if (context.Item.Items.Count > 0)                {                    <GroupedDbVariableGrid Items="@context.Item.Items" />                }            </ChildRowContent>        </MudDataGrid>    </ChildRowContent></MudDataGrid>

Apart from extra styling, hiding headers, it still feels quite some effort to apply uniform column widths this way, but I'm really not sure if this is what you meant. Did you have something vastly different in mind?

@versile2
Comment options

I was suggesting a 1 level hierarchy that handles the initial grouping, and then any additional grouping can be handled inside the rowdetailview. I did forget about the column alignment woes but I usually add some padding around the childrowcontent and leave the header of the child grid so I don't have to worry about it. That's a preference and yes your last example looks pretty close to what I was thinking.

@versile2
Comment options

So your groupeddbvariable grid likely won't have the same woes and can just do regular grouping. If you have more than 1 then using hierarchy column that needs the special grouping you would almost have to be aligned or look odd.

@legrab
Comment options

Given theInitiallyExpandedFunc andButtonDisabledFunc to a Hierarchy always-open programmatically, I am now in the belief the same concept would be a neat way on theGrouping as well.

I haven't checked the code behind, so I might be wrong, but someGroupingExpandedFunc would be quite awesome.

Unfortunately, theGroupExpanded is shared, so that wouldn't really work now.
Would you see handling such function for Expansion (and maybe ButtonDisabled) still too high effort?

@versile2
Comment options

No, that effort level would be probably be in line and acceptable. However, you could probably do this a bit more manually using GroupKeyPath with the public DataGrid method ToggleGroupExpand.

https://mudblazor.com/api/datagrid#methods

/// <summary>/// Represents a read-only, ordered collection of group key values forming a unique path through nested group levels./// Used to identify the exact group or subgroup location in multi-level group scenarios./// </summary>/// <remarks>/// Two <see cref="GroupKeyPath"/> instances are equal if they contain the same elements in the same order./// </remarks>publicclassGroupKeyPath(IList<object?>list):ReadOnlyCollection<object?>(list)

Now I did not implement the GroupKeyPath, someone else did but the code is likely available now to either implement an InitiallyExpandedFunc or something do it manually..

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@legrab@ScarletKuro@versile2

[8]ページ先頭

©2009-2025 Movatter.jp