material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Change row edit delete text

Open Kove11 opened this issue 7 years ago • 8 comments

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?"

Kove11 avatar Jun 25 '19 18:06 Kove11

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

adithyamaheshb avatar Jun 26 '19 23:06 adithyamaheshb

Works like a charm. Thank you!

Kove11 avatar Jun 27 '19 00:06 Kove11

Can we have this custom message with the row data I want to delete?

lekhakomm avatar Aug 27 '20 19:08 lekhakomm

i need custom message to delete relationated with rows field?

gisycu avatar Oct 31 '21 15:10 gisycu

very good. thanks

Nakeva avatar Jan 08 '22 04:01 Nakeva

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.

luis-madrigal avatar Feb 18 '22 08:02 luis-madrigal

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
}

Noble-Shiva avatar Mar 08 '24 06:03 Noble-Shiva

What if, i want to delete the complete message and icons of save and cancel, and just delete the row.

maurya03 avatar Mar 08 '24 07:03 maurya03