简体   繁体   English

如何控制 react-admin 列表上的按钮删除?

[英]How to control the button delete on react-admin list?

How to control the delete button on the react-admin list?如何控制 react-admin 列表中的删除按钮? I need to set a confirmation message before deleting a record.我需要在删除记录之前设置确认消息。 Below is the screenshot of the list:以下是列表截图:

在此处输入图像描述

You can use npm i sweetalert2 like:您可以使用npm i sweetalert2喜欢:

import Swal from "sweetalert2";从“sweetalert2”导入 Swal; import axios from "axios";从“axios”导入 axios;

onDeleteClick( pk) {

    Swal.fire({
      text :"Are you sure?,
      title: "You won't be able to ,
      type: "question",
      showCancelButton: true,
      confirmButtonColor: "#3085d6",
      cancelButtonColor: "#d33",
      confirmButtonText: Yes!,
      cancelButtonText: No!
    }).then(result => {
      if (result.value) {
        axios
          .delete(
            `api ,
            
          )
          .then(res => {
            Swal.fire({
              title: "Deleted",
              type: "success",
              text: " Deleted Successfully !!",
              showConfirmButton: false,
              timer: 2000
            });
          })
          .catch(err => {
            console.log(err);
            Swal.fire({
              title: " Deleted",
              type: "error",
              text: "Error While deleting  ??",
              timer: 3000
            });
          
          });
      }
    });
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM