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

Skip to content

MudDataGrid: Fix StartedEditingItem in cell edit mode#13126

Merged
danielchalmers merged 7 commits into
devfrom
copilot/fix-startededitingitem-event-issue
Jun 23, 2026
Merged

MudDataGrid: Fix StartedEditingItem in cell edit mode#13126
danielchalmers merged 7 commits into
devfrom
copilot/fix-startededitingitem-event-issue

Conversation

Copilot AI commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Fixes StartedEditingItem not firing in DataGridEditMode.Cell. The callback only fired in the form/dialog edit modes, so edit-start workflows such as item snapshotting were unreliable when editing cells:

  • Raise StartedEditingItem when cell editing begins, both on a row click (EditTrigger.OnRowClick) and when a cell input is edited directly. It is raised once per item and again when editing moves to a different item, using the grid's Comparer for item identity (consistent with selection).
  • Keep cell editing clone-free. In cell mode SetEditingItemAsync no longer creates a working-copy clone or opens the edit form; it raises the callback with the source item, which is what cell mode edits in place.
  • Form/dialog edit modes are unchanged.

Cell editing has never cloned the row — it writes changes straight to the source item. Routing the cell path through the normal clone (SystemTextJsonDeepCloneStrategy) throws for item types System.Text.Json cannot round-trip (for example a constructor parameter that does not bind back to a property), which breaks cell editing outright (DataGridEditComplexPropertyExpression). Raising the callback with the live source item keeps the cell path independent of the clone strategy.

<MudDataGrid T="Item" Items="@items" ReadOnly="false"
             EditMode="DataGridEditMode.Cell"
             EditTrigger="DataGridEditTrigger.OnRowClick"
             StartedEditingItem="OnStartedEditingItem">
    <Columns>
        <PropertyColumn Property="x => x.Name" />
    </Columns>
</MudDataGrid>

Tests

  • StartedEditingItem fires on a direct cell edit, on a row click in cell mode, and via SetEditingItemAsync in cell mode; the edit form stays closed and no working copy is created.
  • It is raised once per item, and again when a different item is edited; the dedup honors a custom Comparer.
  • It fires for a non-cloneable item type without throwing.
  • The existing DataGridEventCallbacks test now also asserts the callback during cell editing.

Behavior change

Calling the public SetEditingItemAsync (or CellContext.Actions.StartEditingItemAsync from a custom template) while EditMode is Cell previously opened the form-style edit dialog. It now raises StartedEditingItem and opens nothing, consistent with cell editing writing directly to the source item.

Copilot AI changed the title [WIP] Fix StartedEditingItem event not raised for DataGrid editing Add regression coverage for MudDataGrid.StartedEditingItem in cell edit mode Apr 27, 2026
Copilot AI requested a review from danielchalmers April 27, 2026 12:34
@danielchalmers

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI changed the title Add regression coverage for MudDataGrid.StartedEditingItem in cell edit mode Fix MudDataGrid.StartedEditingItem in cell edit mode Apr 27, 2026
@danielchalmers

This comment was marked as outdated.

Copilot AI commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

...

Fixed in 050cf76. The direct cell-edit path now starts the DataGrid editing session before mutating the row item, so StartedEditingItem fires even when the user edits the cell input without a separate row click. No UI screenshot because this is a non-visual behavior fix.

@danielchalmers

This comment was marked as outdated.

Bring the branch up to date with dev and replace the earlier approach
with a clone-free implementation.

StartedEditingItem never fired in DataGridEditMode.Cell. Raise it both
when a row click starts editing (EditTrigger.OnRowClick) and when a cell
input is edited directly, without re-raising it for further changes on
the same item.

Cell editing writes directly to the source item, so the cell path must
not clone. SetEditingItemAsync now skips the working-copy clone and the
edit form in cell mode and raises the callback with the source item,
which also fixes cell editing throwing for item types the clone strategy
cannot round-trip.
@danielchalmers

Copy link
Copy Markdown
Member

Reopened with a new implementation, brought up to date with dev.

The previous approach started the cell edit through SetEditingItemAsync, which deep-clones the row. Cell editing writes directly to the source item and never cloned before, and that clone throws for item types System.Text.Json can't round-trip — that's what actually failed CI on the last commit (DataGridEditComplexPropertyExpression), not the originally-reported assertion.

This version keeps the cell path clone-free: it raises StartedEditingItem with the live source item and skips the working copy and edit form in cell mode. Form/dialog edit modes are unchanged, and there's a regression test for the non-cloneable case. CI is green.

@danielchalmers danielchalmers marked this pull request as ready for review June 20, 2026 16:51
@mudbot mudbot Bot changed the title Fix MudDataGrid.StartedEditingItem in cell edit mode MudDataGrid: Fix StartedEditingItem in cell edit mode Jun 20, 2026
@mudbot mudbot Bot added the bug Unexpected behavior or functionality not working as intended label Jun 20, 2026
Use the grid's Comparer (the same identity used for selection) to decide
whether cell editing has moved to a new item, instead of hard-coded
EqualityComparer<T>.Default. This lets a custom comparer distinguish
otherwise-equal rows such as records. The first edit always starts since
nothing is being edited yet.
@danielchalmers danielchalmers removed their assignment Jun 20, 2026
This was referenced Jul 2, 2026
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.

StartedEditingItem event is not raised when editing DataGrid item if EditTrigger is set to OnRowClick and DataGridEditMode is set to Cell

2 participants