不要在Material Table中验证删除。
创始人
2025-01-11 02:30:26
0

要在Material Table中验证删除,可以使用onRowDelete属性来处理删除操作,并在删除之前进行验证。

以下是一个示例代码:

import React from 'react';
import MaterialTable from 'material-table';
import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css';

export default function App() {
  const data = [
    { id: 1, name: 'John Doe', age: 25 },
    { id: 2, name: 'Jane Smith', age: 30 },
    { id: 3, name: 'Bob Johnson', age: 35 },
  ];

  const columns = [
    { title: 'ID', field: 'id' },
    { title: 'Name', field: 'name' },
    { title: 'Age', field: 'age' },
  ];

  const handleDelete = (oldData) => {
    confirmAlert({
      title: 'Confirm Delete',
      message: 'Are you sure you want to delete this row?',
      buttons: [
        {
          label: 'Yes',
          onClick: () => {
            // Perform delete operation here
            const newData = [...data];
            const index = data.indexOf(oldData);
            newData.splice(index, 1);
            setData(newData);
          },
        },
        {
          label: 'No',
          onClick: () => {},
        },
      ],
    });
  };

  const [tableData, setData] = React.useState(data);

  return (
    
          new Promise((resolve, reject) => {
            handleDelete(oldData);
            resolve();
          }),
      }}
    />
  );
}

在上面的代码中,我们使用了react-confirm-alert库来显示一个确认对话框来验证删除操作。当用户点击“Yes”按钮时,我们执行实际的删除操作,并更新表格的数据。当用户点击“No”按钮时,我们不执行任何操作。

注意:为了运行上述代码,您需要安装react-confirm-alertmaterial-table库,并在代码中进行适当的导入。

相关内容

热门资讯

透视软件!hhpoker透视脚... 透视软件!hhpoker透视脚本视频,wpk透视辅助方法,普及教程(起初是有挂);亲,其实确实真的有...
透视透视!德普之星app安卓版... 透视透视!德普之星app安卓版破解版,wepoker有没有插件,透牌教程(起初真的有挂);德普之星a...
透视透视!wepoker免费永... 透视透视!wepoker免费永久脚本,wepoker怎么破解游戏,科技教程(原生有挂);wepoke...
透视黑科技!aapoker辅助... 自定义aapoker辅助挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,...
透视了解!aapoker可以开... 透视了解!aapoker可以开挂吗,wepoker透视脚本是什么,普及教程(一直是有挂);免费aap...
透视智能ai!wpk辅助器下载... 透视智能ai!wpk辅助器下载,aapoker怎么提高中牌率,规律教程(起初真的是有挂);致您一封信...
透视好友!德普之星辅助功能如何... 透视好友!德普之星辅助功能如何设置,约局吧开挂神器是真的吗,攻略教程(好像真的有挂);德普之星辅助功...
透视系统!wepoker透视脚... 透视系统!wepoker透视脚本网页,wpk作弊最怕三个东西,可靠技巧(本来是真的有挂);亲们利用一...
透视好友房!wepoker透视... 透视好友房!wepoker透视底牌脚本,德普之星透视辅助软件,微扑克教程(素来真的有挂)需要回顾用户...
透视科技!红龙poker脚本,... 透视科技!红龙poker脚本,德普之星透视辅助软件,wepoke教程(先前有挂);德普之星透视辅助软...