| Ms. | Nancy | Davolio | Sales Representative | (206) 555-9857 | Seattle | 12/8/1988 | 5/1/2023 | |
| Dr. | Andrew | Fuller | Vice President, Sales | (206) 555-9482 | Tacoma | 2/19/1975 | 8/14/2010 | |
| Ms. | Janet | Leverling | Sales Representative | (206) 555-3412 | Kirkland | 8/30/1995 | 4/1/2020 | |
| Mrs. | Margaret | Peacock | Sales Representative | (206) 555-8122 | Redmond | 9/19/1983 | 5/3/2011 | |
| Mr. | Steven | Buchanan | Sales Manager | (71) 555-4848 | London | 3/4/1970 | 10/17/2011 | |
| Mr. | Michael | Suyama | Sales Representative | (71) 555-7773 | London | 7/2/1991 | 10/17/2017 | |
| Mr. | Robert | King | Sales Representative | (71) 555-5598 | London | 5/29/1970 | 1/2/2012 | |
| Ms. | Laura | Callahan | Inside Sales Coordinator | (206) 555-1189 | Seattle | 1/9/1995 | 3/5/2022 | |
| Ms. | Anne | Dodsworth | Sales Representative | (71) 555-4444 | London | 1/27/1990 | 11/15/2022 | |
In this demo, the DevExpress Blazor Grid displays an in-place editor when a user clicks a data cell. Users can edit the current cell and activate editors for other cells within the same row. When focus moves to a different row, the component validates user input and saves changes.
To enable cell editing:
- Set the EditMode property to
EditCell. - If your data object has a primary key, assign it to the KeyFieldName or KeyFieldNames property. The Grid uses field values to compare and identify data items. If you do not specify these properties, the Grid uses standard .NET value equality comparison to identify data items.
- (Optional) Declare a DxGridCommandColumn object in the Columns template to allow users to create and delete data rows. In addition to predefined New and Delete buttons, this column displays Edit, Save, and Cancel commands that are redundant in cell editing mode. Disable EditButtonVisible, CancelButtonVisible, and SaveButtonVisible properties to hide these buttons.
- Handle the following events to make final data changes, check access permissions, post changes to the underlying data source, and reload Grid data:
- EditModelSaving — Fires when a user saves the edited row and validation passes.
- DataItemDeleting — Fires when a user confirms the delete operation in the delete confirmation dialog.
- (Optional) Handle the CustomizeEditModel event to initialize an edit model for new data rows.
You can use the following keyboard shortcuts in cell editing mode:
Enter / Shift+Enter
Opens an in-place editor for the focused cell (if not already open).
If an in-place editor is already open, Enter applies changes and closes the editor. Focus can then move to the next/previous cell depending on the EnterKeyDirection property. If the EditNextCellOnEnter option is enabled, the Grid component opens an in-place editor in the next cell. Use checkboxes above the component to try these options.
Note: Shift+Enter moves focus in the opposite direction.
Esc
Hides the in-place editor and discards changes made in that cell.
If the in-place editor is hidden, discards all changes made in the row and cancels row editing.
Tab / Shift+Tab
Hides the editor, focuses the next/previous data cell, and displays an editor in the newly focused cell.
Start typing in a focused cell
When the EditOnKeyPress property is enabled, users can start editing a cell by entering a value within it. The editor opens automatically and accepts entered characters. Select the Edit on Key Press option to try it out.
In this demo, you can open a context menu to test edit cell mode in combination with other Grid features.
For additional information on how you can enable data editing and use edit-related options, refer to the following help topic: Edit Cell.