简体   繁体   中英

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

How to control the delete button on the react-admin list? 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:

import Swal from "sweetalert2"; import axios from "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
            });
          
          });
      }
    });
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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