From 61cfdde73f5429f28577b6d2fc73a6229885dccf Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 29 Jan 2021 21:18:19 +0300 Subject: [PATCH] Fixed #1788 - Improve rowEditor buttons on DataTable with editMode="row" --- src/components/datatable/BodyCell.js | 38 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/components/datatable/BodyCell.js b/src/components/datatable/BodyCell.js index 9d94c41d00..7e868da957 100644 --- a/src/components/datatable/BodyCell.js +++ b/src/components/datatable/BodyCell.js @@ -189,7 +189,7 @@ export class BodyCell extends Component { onClick: this.onExpanderClick, className: "p-row-toggler p-link", iconClassName, - defaultElement: content + element: content }; content = this.props.body(this.props.rowData, { ...this.props, ...{expander: expanderProps} }); @@ -222,28 +222,52 @@ export class BodyCell extends Component { } } else if (this.props.rowEditor) { + let rowEditorProps = {}; + if (this.state.editing) { + rowEditorProps = { + editing: true, + onSaveClick: this.props.onRowEditSave, + saveClassName: 'p-row-editor-save p-link', + saveIconClassName: 'p-row-editor-save-icon pi pi-fw pi-check p-clickable', + onCancelClick: this.props.onRowEditCancel, + cancelClassName: 'p-row-editor-cancel p-link', + cancelIconClassName: 'p-row-editor-cancel-icon pi pi-fw pi-times p-clickable' + }; + content = ( <> - - ); } else { + rowEditorProps = { + editing: false, + onInitClick: this.props.onRowEditInit, + initClassName: 'p-row-editor-init p-link', + initIconClassName: 'p-row-editor-init-icon pi pi-fw pi-pencil p-clickable' + }; + content = ( - ); } + + if (this.props.body) { + rowEditorProps['element'] = content; + content = this.props.body(this.props.rowData, { ...this.props, ...{rowEditor: rowEditorProps} }); + } } else { if (this.state.editing && this.props.editor) {