Add inline cell editing#827
Open
lukasbash7 wants to merge 3 commits into
Open
Conversation
Mark any column as editable and provide an onCellEdit handler to enable
double-click inline editing. A plain unstyled <input> is used as the
built-in fallback; columns can supply an editRender function to render any
custom control (e.g. a Select dropdown).
Per-column options:
- editable: true | (record, index) => boolean
- editRender: (record, index, context) => ReactNode
- commitEditOn: ('blur' | 'enter')[] (default: both)
Table-level options:
- onCellEdit: ({ record, index, accessor, value }) => void
- defaultCommitEditOn: ('blur' | 'enter')[]
- editMode: 'cell' (default) | 'global'
- editingCellStyle / editingCellClassName: style the focused cell's <td>
In global mode all editable cells are in edit state at once; Tab /
Shift+Tab navigate between them. Existing callbacks continue to fire.
Four examples on /examples/editing-cells: - Basic editable columns with onCellEdit updating local state - Per-cell editability using the editable predicate function - onCellEdit callback with a visible commit log showing the payload shape - Custom editRender with a Mantine Select (single-event commit via onCommit) - Global edit mode (editMode="global") with Tab/Shift-Tab cell navigation and focused-cell highlight via editingCellStyle
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Author
|
@icflorescu I tried to generalize #767 with this PR and allow the users to define their own rendering behavior so the table does not have to deal too much with specifics. Would be great if you could take a look. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Inline cell editing triggered by double-click, with a plain unstyled
<input>as the built-in fallback and full support for custom edit controls viaeditRender.Per-column options
editableboolean | (record, index) => booleaneditRender(record, index, context) => ReactNodecommitEditOn('blur' | 'enter')[]Table-level options
onCellEdit({ record, index, accessor, value }) => voiddefaultCommitEditOn('blur' | 'enter')[]editMode'cell' | 'global''cell': double-click one cell at a time (default);'global': all editable cells in edit state simultaneouslyeditingCellStyleMantineStyleProp<td>editingCellClassNamestring<td>Behaviour
editModeprop (global mode)onCellClick,onCellDoubleClick,onCellContextMenu, etc.) continue to fire normallyeditRenderreceives{ value, onChange, onCommit, onCancel }—onCommit(value)lets controls likeSelectcommit in a single eventExamples
Four examples added to
/examples/editing-cells:editablepredicateonCellEditcallback with a visible commit log showing the payload shapeeditRenderwith a MantineSelect