From 5fab88f1dc3230c54dd60b4b080d9d4b83dd7440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Belniak?= Date: Sun, 11 Feb 2024 13:45:28 +0100 Subject: [PATCH] #2424 Improve row edit validation api - add rowIndex to rowEditValidator, add newData to onRowEditSave (#5938) --- components/doc/common/apidoc/index.json | 18 ++++++++++++++++-- components/lib/datatable/BodyRow.js | 3 ++- components/lib/datatable/datatable.d.ts | 12 ++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/components/doc/common/apidoc/index.json b/components/doc/common/apidoc/index.json index baa19e37e4..96cb47f9e9 100644 --- a/components/doc/common/apidoc/index.json +++ b/components/doc/common/apidoc/index.json @@ -17327,7 +17327,7 @@ { "name": "event", "optional": false, - "type": "DataTableRowEditSaveEvent", + "type": "DataTableRowEditSaveEvent", "description": "Custom row edit save event." } ], @@ -18617,6 +18617,13 @@ "readonly": false, "type": "boolean", "description": "Whether the row is valid or not." + }, + { + "name": "newData", + "optional": false, + "readonly": false, + "type": "DataTableRowData", + "description": "Editing row data." } ], "callbacks": [], @@ -18751,6 +18758,13 @@ "readonly": false, "type": "DataTableProps", "description": "The props of the datatable." + }, + { + "name": "rowIndex", + "optional": false, + "readonly": false, + "type": "number", + "description": "Index of validated row" } ], "callbacks": [] @@ -20270,7 +20284,7 @@ { "name": "event", "optional": false, - "type": "DataTableRowEditSaveEvent", + "type": "DataTableRowEditSaveEvent", "description": "Custom row edit save event." } ], diff --git a/components/lib/datatable/BodyRow.js b/components/lib/datatable/BodyRow.js index a5ce074112..f189119c23 100644 --- a/components/lib/datatable/BodyRow.js +++ b/components/lib/datatable/BodyRow.js @@ -358,13 +358,14 @@ export const BodyRow = React.memo((props) => { const onEditSave = (e) => { const { originalEvent: event, newData } = e; - const valid = props.rowEditValidator ? props.rowEditValidator(newData, { props: props.tableProps }) : true; + const valid = props.rowEditValidator ? props.rowEditValidator(newData, { props: props.tableProps, rowIndex: props.rowIndex }) : true; if (props.onRowEditSave) { props.onRowEditSave({ originalEvent: event, data: props.rowData, index: props.rowIndex, + newData, valid }); } diff --git a/components/lib/datatable/datatable.d.ts b/components/lib/datatable/datatable.d.ts index 012a974003..f4bcec5ae1 100644 --- a/components/lib/datatable/datatable.d.ts +++ b/components/lib/datatable/datatable.d.ts @@ -511,11 +511,15 @@ interface DataTableRowEditEvent extends DataTableRowEvent { * @see {@link DataTableProps.onRowEditSave} * @extends DataTableRowEditEvent */ -interface DataTableRowEditSaveEvent extends DataTableRowEditEvent { +interface DataTableRowEditSaveEvent extends DataTableRowEditEvent { /** * Whether the row is valid or not. */ valid: boolean; + /** + * Editing row data. + */ + newData: DataTableRowData; } /** @@ -732,6 +736,10 @@ interface DataTableRowEditValidatorOptions { * The props of the datatable. */ props: DataTableProps; + /** + * Index of validated row + */ + rowIndex: number; } /** @@ -1556,7 +1564,7 @@ interface DataTableBaseProps extends Omit): void; /** * Callback to invoke when a row is expanded. * @param {DataTableRowEvent} event - Custom row event.