Skip to content

Commit

Permalink
#2424 Improve row edit validation api - add rowIndex to rowEditValida…
Browse files Browse the repository at this point in the history
…tor, add newData to onRowEditSave (#5938)
  • Loading branch information
MBelniak authored Feb 11, 2024
1 parent d6f49ca commit 5fab88f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 16 additions & 2 deletions components/doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -17327,7 +17327,7 @@
{
"name": "event",
"optional": false,
"type": "DataTableRowEditSaveEvent",
"type": "DataTableRowEditSaveEvent<TValue>",
"description": "Custom row edit save event."
}
],
Expand Down Expand Up @@ -18617,6 +18617,13 @@
"readonly": false,
"type": "boolean",
"description": "Whether the row is valid or not."
},
{
"name": "newData",
"optional": false,
"readonly": false,
"type": "DataTableRowData<TValue>",
"description": "Editing row data."
}
],
"callbacks": [],
Expand Down Expand Up @@ -18751,6 +18758,13 @@
"readonly": false,
"type": "DataTableProps<TValue>",
"description": "The props of the datatable."
},
{
"name": "rowIndex",
"optional": false,
"readonly": false,
"type": "number",
"description": "Index of validated row"
}
],
"callbacks": []
Expand Down Expand Up @@ -20270,7 +20284,7 @@
{
"name": "event",
"optional": false,
"type": "DataTableRowEditSaveEvent",
"type": "DataTableRowEditSaveEvent<TValue>",
"description": "Custom row edit save event."
}
],
Expand Down
3 changes: 2 additions & 1 deletion components/lib/datatable/BodyRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
12 changes: 10 additions & 2 deletions components/lib/datatable/datatable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,15 @@ interface DataTableRowEditEvent extends DataTableRowEvent {
* @see {@link DataTableProps.onRowEditSave}
* @extends DataTableRowEditEvent
*/
interface DataTableRowEditSaveEvent extends DataTableRowEditEvent {
interface DataTableRowEditSaveEvent<TValue extends DataTableValueArray> extends DataTableRowEditEvent {
/**
* Whether the row is valid or not.
*/
valid: boolean;
/**
* Editing row data.
*/
newData: DataTableRowData<TValue>;
}

/**
Expand Down Expand Up @@ -732,6 +736,10 @@ interface DataTableRowEditValidatorOptions<TValue extends DataTableValueArray> {
* The props of the datatable.
*/
props: DataTableProps<TValue>;
/**
* Index of validated row
*/
rowIndex: number;
}

/**
Expand Down Expand Up @@ -1556,7 +1564,7 @@ interface DataTableBaseProps<TValue extends DataTableValueArray> extends Omit<Re
* Callback to invoke when the save icon is clicked on row editing mode.
* @param {DataTableRowEditSaveEvent} event - Custom row edit save event.
*/
onRowEditSave?(event: DataTableRowEditSaveEvent): void;
onRowEditSave?(event: DataTableRowEditSaveEvent<TValue>): void;
/**
* Callback to invoke when a row is expanded.
* @param {DataTableRowEvent} event - Custom row event.
Expand Down

0 comments on commit 5fab88f

Please sign in to comment.