Change row edit delete text
Is it possible to change the text that appears when deleting a row. I want different text than the default "Are you sure delete this row?"
You can modify it in the localization props. For example
localization={{
body: {
editRow: { deleteText: 'Customized Delete Message' }
}
}}
Check the documentation for more localization props.
https://material-table.com/#/docs/all-props
Works like a charm. Thank you!
Can we have this custom message with the row data I want to delete?
i need custom message to delete relationated with rows field?
very good. thanks
For those looking for a way to change the message depending on row data, hacked together this workaround:
components={{
Body: (props) => {
let _props = props;
const editingRow = tableRef.current?.state?.lastEditingRow;
if (onDeleteLabel && editingRow) {
_props = {
...props,
localization: {
...props.localization,
editRow: {
...props.editRow,
deleteText: onDeleteLabel(editingRow),
},
},
};
}
return <MTableBody {..._props} />;
},
}}
Where onDeleteLabel is a function that returns a string based on row data
I had to update the localization text for row delete by overriding the table's body component.
The above code will not work with "@material-table/core": "^6.1.13" version as the localization "prop" is not present on the body props anymore. Is it possible to provide a different solution?
props on body
{
"actions": [
{
"tooltip": "Remove All Selected Rows",
"icon": "delete",
"hidden": false,
"position": "toolbarOnSelect"
},
{
"tooltip": "CopyRow",
"icon": "copy_all",
"hidden": true,
"position": "toolbarOnSelect"
},
{
"tooltip": "PasteRow",
"icon": "content_paste",
"hidden": true,
"position": "toolbarOnSelect"
},
{
"tooltip": "Import",
"hidden": true,
"isFreeAction": true,
"position": "toolbar"
},
{
"tooltip": "Refresh",
"hidden": true,
"isFreeAction": true,
"position": "toolbar"
},
{
"tooltip": "Extract",
"hidden": true,
"isFreeAction": true,
"position": "toolbar"
},
{
"tooltip": "Add",
"position": "toolbar",
"disabled": false
},
null,
null
],
"components": {
"Action": {},
"Actions": {},
"Cell": {},
"Container": {},
"EditRow": {},
"FilterRow": {},
"Groupbar": {},
"GroupRow": {},
"Header": {
"type": {},
"compare": null
},
"OverlayLoading": {},
"OverlayError": {}
},
"renderData": [
{
"name": "en",
"desc": "English",
"textdirection": "LTR",
"id": "uuid-29191398470000000",
"tableData": {
"index": 0,
"id": "uuid-29191398470000000",
"uuid": "f3f4df4e-cb29-414d-b8c7-e793f38ad26d",
"editing": "delete"
}
}
],
"data": [
{
"name": "en",
"desc": "English",
"textdirection": "LTR",
"id": "uuid-29191398470000000",
"tableData": {
"index": 0,
"id": "uuid-29191398470000000",
"uuid": "f3f4df4e-cb29-414d-b8c7-e793f38ad26d",
"editing": "delete"
}
}
],
"currentPage": 0,
"pageSize": 5,
"columns": [
{
"title": "Code",
"field": "name",
"width": 100,
"tableData": {
"columnOrder": 0,
"groupSort": "asc",
"width": "100px",
"initialWidth": "100px",
"widthPx": 100,
"additionalWidth": 0,
"id": 0
}
},
{
"title": "Description",
"field": "desc",
"width": 200,
"tableData": {
"columnOrder": 1,
"groupSort": "asc",
"width": "200px",
"initialWidth": "200px",
"widthPx": 200,
"additionalWidth": 0,
"id": 1
}
}
],
"options": {
"idSynonym": "id",
"actionsColumnIndex": -1,
"addRowPosition": "last",
"columnsButton": false,
"detailPanelType": "multiple",
"debounceInterval": 200,
"doubleHorizontalScroll": false,
"emptyRowsWhenPaging": true,
"exportAllData": true,
"exportMenu": [],
"filtering": false,
"groupTitle": false,
"header": true,
"headerSelectionProps": {},
"hideFilterIcons": false,
"loadingType": "overlay",
"padding": "normal",
"searchAutoFocus": false,
"paging": false,
"pageSize": 5,
"pageSizeOptions": [
5,
10,
20,
30,
50,
75,
100
],
"paginationType": "normal",
"paginationPosition": "bottom",
"showEmptyDataSourceMessage": true,
"showFirstLastPageButtons": true,
"showSelectAllCheckbox": true,
"showSelectGroupCheckbox": true,
"search": false,
"showTitle": true,
"showTextRowsSelected": true,
"showDetailPanelIcon": true,
"tableLayout": "auto",
"tableWidth": "full",
"toolbarButtonAlignment": "right",
"searchFieldAlignment": "left",
"searchFieldStyle": {},
"searchFieldVariant": "standard",
"selection": true,
"selectionProps": {},
"maxColumnSort": 1,
"groupChipProps": {},
"defaultOrderByCollection": [],
"showColumnSortOrder": false,
"keepSortDirectionOnColumnSwitch": true,
"toolbar": true,
"defaultExpanded": false,
"detailPanelColumnAlignment": "left",
"detailPanelOffset": {
"left": 0,
"right": 0
},
"thirdSortClick": true,
"overflowY": "auto",
"numberOfPagesAround": 1,
"actionsHeaderIndex": 0,
"draggable": true,
"rowStyle": {
"color": "#f1efef"
},
"headerStyle": {
"backgroundColor": "#424242",
"color": "#f1efef",
"fontWeight": "bold",
"paddingTop": 0,
"paddingBottom": 0
}
},
"isTreeData": false,
"showAddRow": false,
"hasAnyEditingRow": true,
"hasDetailPanel": false,
"treeDataMaxLevel": 0,
"bulkEditOpen": false,
"bulkEditChangedRows": {},
"scrollWidth": 1116
}
What if, i want to delete the complete message and icons of save and cancel, and just delete the row.