'Create a delete button in DataTable with Ajax query

I'm trying to create a delete button in my DataTable which deletes data from a database.

I have created the icon button, but I don't know how to insert a 'delete' function in to the DataTable.

I think I have to use an AJAX request to call PHP to delete the row in the DataTable. I have tried some stuff, but nothing works.

$("#tab").dataTable({
  serverSide: false,
  ajax: {
    type: "GET",
    url: plugin_ajax_object.ajax_url,
    dataSrc: "", // Aller sur un fichier php pour aovir une url
  },
  columns: [
    { data: "david_enable", },
    { data: "david_nom", },
    { data: "david_url", },
    { data: "david_cms", },
    {
      data: "david_site_id",
      render: function(data, type, row) {
        return `<a href="admin.php?page=enable.php${data}" class="dashicons-before dashicons-edit">Activer</a><br>
          <a class="dashicons-before dashicons-trash" id="Delete">Supprimer</a><br>`
      }
    }
  ],
  createdRow: function(row, data, dataIndex) {
    if (data["david_enable"] == null) {
      $(row).addClass('bg-danger');
    }
  },
  createdRow: function(row, data, dataIndex) {},
  language: {
    lengthMenu: "Afficher _MENU_ éléments",
    search: "Rechercher :",
    info: "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
    paginate: {
      first: "Premier",
      last: "Dernier",
      next: "Suivant",
      previous: "Précédent",
    },
    infoEmpty: "",
    emptyTable: "",
    zeroRecords: "",
    loadingRecords: "Chargement...",
    processing: "En cours...",
  },
  pagingType: "simple_numbers",
  lengthMenu: [10, 20, 30],
  pageLength: 10,
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source