MudDataGrid: Fix StartedEditingItem in cell edit mode#13126
Conversation
Agent-Logs-Url: https://github.com/MudBlazor/MudBlazor/sessions/3d85d17d-3da8-446e-8784-036a8e992a83 Co-authored-by: danielchalmers <[email protected]>
MudDataGrid.StartedEditingItem in cell edit mode
This comment was marked as outdated.
This comment was marked as outdated.
Agent-Logs-Url: https://github.com/MudBlazor/MudBlazor/sessions/73d55425-778c-410f-ae7c-db30982166b6 Co-authored-by: danielchalmers <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
MudDataGrid.StartedEditingItem in cell edit modeMudDataGrid.StartedEditingItem in cell edit mode
This comment was marked as outdated.
This comment was marked as outdated.
Agent-Logs-Url: https://github.com/MudBlazor/MudBlazor/sessions/192aa893-76c7-4536-9373-ccb220de052d Co-authored-by: danielchalmers <[email protected]>
This comment was marked as outdated.
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.
|
Reopened with a new implementation, brought up to date with The previous approach started the cell edit through This version keeps the cell path clone-free: it raises |
MudDataGrid.StartedEditingItem in cell edit modeUse 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.
Fixes
StartedEditingItemnot firing inDataGridEditMode.Cell. The callback only fired in the form/dialog edit modes, so edit-start workflows such as item snapshotting were unreliable when editing cells:StartedEditingItemwhen 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'sComparerfor item identity (consistent with selection).SetEditingItemAsyncno 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.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.Tests
StartedEditingItemfires on a direct cell edit, on a row click in cell mode, and viaSetEditingItemAsyncin cell mode; the edit form stays closed and no working copy is created.Comparer.DataGridEventCallbackstest now also asserts the callback during cell editing.Behavior change
Calling the public
SetEditingItemAsync(orCellContext.Actions.StartEditingItemAsyncfrom a custom template) whileEditModeisCellpreviously opened the form-style edit dialog. It now raisesStartedEditingItemand opens nothing, consistent with cell editing writing directly to the source item.