-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MudDataGrid: Allow disabling selection per row via criteria #11554
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
base: dev
Are you sure you want to change the base?
MudDataGrid: Allow disabling selection per row via criteria #11554
Conversation
…ithub.com/Anu6is/MudBlazor into 11546-MudDataGrid-DisableSelection-PerRow
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #11554 +/- ##
==========================================
+ Coverage 91.31% 91.33% +0.02%
==========================================
Files 466 466
Lines 14725 14768 +43
Branches 2870 2871 +1
==========================================
+ Hits 13446 13489 +43
Misses 636 636
Partials 643 643 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean updates. While the proper null checks are in place I think those two should still be "nullable" for form and a better doc would always help others.
|
real cool docs update. I like it. |
|
|
Does this pull request has been merged? |
|
I have another question according to this. Maybe a bit late. But is it possible to automatically unselect a selected row, when the row is then filtered and hence hidden? |
|
That's an interesting question about how filtering should interact with selections. For usage questions and discussions about potential new behavior, the best places to get input from the community and maintainers are our support channels. For similar topics or broader help, you're welcome to use GitHub Discussions or our Discord community. I'm an AI assistant — If I missed something or made a mistake, please let me know in a reply! |
|
@BigBasti123 not really related to this change. However, you could probably utilize a custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for disabling specific rows in the DataGrid's SelectColumn through a new DisabledFunc parameter. The implementation refactors SelectColumn to inherit from TemplateColumn and ensures disabled rows cannot be selected via checkboxes, row clicks, or "select all" operations.
Key Changes:
- Added
DisabledFuncparameter to SelectColumn for conditional row selection disabling - Refactored SelectColumn to inherit from TemplateColumn with overridden template properties
- Enhanced selection logic to respect disabled state in individual and bulk operations
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| SelectColumn.razor.cs | Refactored to inherit from TemplateColumn, added DisabledFunc parameter, removed redundant properties now inherited from base class |
| SelectColumn.razor | Moved template logic to code methods, integrated DisabledFunc into checkbox rendering |
| MudDataGrid.razor.cs | Updated SetSelectedItemAsync and SetSelectAllAsync to check and respect DisabledFunc |
| HeaderContext.cs | Added IsMultiSelection property for conditional header checkbox rendering |
| FooterContext.cs | Added IsMultiSelection property for conditional footer checkbox rendering |
| Column.razor.cs | Made template properties virtual to allow overriding in derived classes |
| DataGridTests.cs | Added comprehensive test coverage for DisabledFunc functionality |
| DataGridSelectionExample.razor | Updated example to demonstrate DisabledFunc usage |
| DataGridPage.razor | Added documentation section for row selection features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ValueChanged="@context.Actions.SetSelectedItemAsync" | ||
| Disabled="@(DisabledFunc?.Invoke(context.Item) ?? false)" />; | ||
|
|
||
| #nullable enable |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate #nullable enable directive. Line 6 already enables nullable reference types for this code block, making line 27 redundant.
| #nullable enable |
| public override RenderFragment<HeaderContext<T>>? HeaderTemplate { get => ShowInHeader ? GetHeaderTemplate() : null; set { } } | ||
| public override RenderFragment<CellContext<T>> CellTemplate { get => GetCellTemplate(); set { } } | ||
| public override RenderFragment<FooterContext<T>>? FooterTemplate { get => ShowInFooter ? GetFooterTemplate() : null; set { } } |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getter methods create new RenderFragment delegates on every access. Consider caching these delegates if the properties are accessed multiple times during rendering, or ensuring that ShowInHeader/ShowInFooter changes trigger proper re-initialization.
| @@ -1,10 +1,12 @@ | |||
| @using System.Net.Http.Json | |||
| @using System.Net.Http.Json | |||
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains duplicate BOM characters (two UTF-8 BOMs). This should be cleaned to have only one BOM at the start of the file.
| @using System.Net.Http.Json | |
| @using System.Net.Http.Json |
| new TestDataItem { Id = 2, Name = "Disabled Item 1", ShouldBeDisabled = true }, | ||
| new TestDataItem { Id = 3, Name = "Enabled Item 2", ShouldBeDisabled = false } | ||
| }; | ||
| Func<TestDataItem, bool> disabledFunc = item => item.ShouldBeDisabled; |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to disabledFunc is useless, since its value is never read.
| Func<TestDataItem, bool> disabledFunc = item => item.ShouldBeDisabled; |
| new TestDataItem { Id = 3, Name = "Enabled Item 2", ShouldBeDisabled = false }, | ||
| new TestDataItem { Id = 4, Name = "Disabled Item 2", ShouldBeDisabled = true } | ||
| }; | ||
| Func<TestDataItem, bool> disabledFunc = item => item.ShouldBeDisabled; |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to disabledFunc is useless, since its value is never read.
| Func<TestDataItem, bool> disabledFunc = item => false; // All items are effectively enabled | ||
|
|
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to disabledFunc is useless, since its value is never read.
| Func<TestDataItem, bool> disabledFunc = item => false; // All items are effectively enabled |
|
I guess it's breaking change because |
|
@ScarletKuro |



Description
Created a new
DisabledFuncparameter in theSelectColumnto allow for conditionally disabling the select checkbox.The following applies once disabled
Additionally, the select all checkbox has been hidden from the header and footer when
MultiSelectionisfalse.Resolves #11546
Resolves #11500
The documentation page includes an example of using this function.
How Has This Been Tested?
Visually and unit tests
Type of Changes
Docs:

Demo:
disable.mod.5.mp4
Checklist
dev).