Skip to content

Conversation

@Anu6is
Copy link
Contributor

@Anu6is Anu6is commented Jun 25, 2025

Description

Created a new DisabledFunc parameter in the SelectColumn to allow for conditionally disabling the select checkbox.
The following applies once disabled

  • The checkbox is disabled
  • Select on row click is ignored
  • Select all does not select the row

Additionally, the select all checkbox has been hidden from the header and footer when MultiSelection is false .

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

  • 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)

Docs:
image


Demo:

disable.mod.5.mp4

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 the enhancement Request for adding a new feature or enhancing existing functionality (not fixing a defect) label Jun 25, 2025
@codecov
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.33%. Comparing base (1b5ac83) to head (fb99c5b).

Files with missing lines Patch % Lines
...udBlazor/Components/DataGrid/SelectColumn.razor.cs 91.66% 0 Missing and 1 partial ⚠️
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.
📢 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.

@Anu6is Anu6is requested review from ScarletKuro and tjscience June 25, 2025 18:41
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.

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.

@versile2
Copy link
Contributor

versile2 commented Jul 1, 2025

real cool docs update. I like it.

@github-actions github-actions bot added the awaiting triage Needs maintainer review or assistance label Aug 3, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 7, 2025

@danielchalmers danielchalmers removed the awaiting triage Needs maintainer review or assistance label Aug 17, 2025
@ProgramGeek02
Copy link

Does this pull request has been merged?

@BigBasti123
Copy link

BigBasti123 commented Oct 21, 2025

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?

@mudbot
Copy link

mudbot bot commented Oct 21, 2025

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!

@Anu6is
Copy link
Contributor Author

Anu6is commented Oct 21, 2025

@BigBasti123 not really related to this change. However, you could probably utilize a custom FilterTemplate that either clears all selected items when applying the filter or clears items not in the FilteredItems list after the filter is applied.

Copy link
Contributor

Copilot AI left a 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 DisabledFunc parameter 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
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
#nullable enable

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +57
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 { } }
Copy link

Copilot AI Oct 30, 2025

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.

Copilot uses AI. Check for mistakes.
@@ -1,10 +1,12 @@
@using System.Net.Http.Json
@using System.Net.Http.Json
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
@using System.Net.Http.Json
@using System.Net.Http.Json

Copilot uses AI. Check for mistakes.
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;
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
Func<TestDataItem, bool> disabledFunc = item => item.ShouldBeDisabled;

Copilot uses AI. Check for mistakes.
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;
Copy link

Copilot AI Oct 30, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +5531 to +5532
Func<TestDataItem, bool> disabledFunc = item => false; // All items are effectively enabled

Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
Func<TestDataItem, bool> disabledFunc = item => false; // All items are effectively enabled

Copilot uses AI. Check for mistakes.
@ScarletKuro
Copy link
Member

I guess it's breaking change because DragAndDropEnabled is gone from SelectColumn

@mudbot mudbot bot added the breaking change This change will require consumer code updates label Oct 30, 2025
@Anu6is
Copy link
Contributor Author

Anu6is commented Oct 30, 2025

@ScarletKuro DragAndDropEnabled is still available since SelectColumn now inherits from TemplateColumn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This change will require consumer code updates 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.

Support disabling row checkbox per item in MudDataGrid SelectColumn Selection Checkbox in Header Should Be Hidden when MultiSelection is False

6 participants