如何从数据表中获取删除按钮名称以进行模式确认删除

时间:2020-03-27 18:37:21

标签: javascript jquery twitter-bootstrap datatable

我正在尝试创建一个模式弹出窗口(使用Bootstrap)以确认该数据表中的行已删除。

如何在此Datable中调用delete函数,这样我可以告诉我的模式弹出以确认删除?

我不确定这是否有意义,但我希望在这里继续进行就可以了。

$(document).ready(function () {
  $('#Test1').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": {
      url: "@Url.Action("LoadData", "Test1")",
      type: 'POST'
    },
    "columns": [
      {"data": 'Test2'},
      {"data": 'Test3'},
      {"data": 'Test4'},
      {"data": 'Test5'},
      {"data": 'Test6'},
      {"data": 'Test7'},
      {"data": 'Actions',
       "render": function(data, type, row, meta) {
         return "<a href = '@Url.Action("Edit", "Test1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title = \"Edit\"><i class='icon-edit fa fa-pencil fa-fw fa-lg'></i></a>" +
           "<a href='@Url.Action("Copy", "CopyTest1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title=\"Duplicate\"><i class='icon-replicate fa fa-clipboard fa-fw fa-lg'></i></a>" +
             "<a href='@Url.Action("Delete", "Test1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title=\"Delete\"><i class='icon-red fa fa-times fa-lg fa-fw'></i></a>" ;
       }
      }
    ],
    "columnDefs": [ {
      "targets": [-1],
      "orderable": false,
      "searchable": false
    } ]

  });
  console.log("ready to work");
});

1 个答案:

答案 0 :(得分:0)

或者您可以使用JavaScript Window confirm() Method

$(document).ready(function () {
    $('#Test1').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            url: "@Url.Action("LoadData", "Test1")",
            type: 'POST'
        },
        "columns": [
            {"data": 'Test2'},
            {"data": 'Test3'},
            {"data": 'Test4'},
            {"data": 'Test5'},
            {"data": 'Test6'},
            {"data": 'Test7'},
            {"data": 'Actions',
                "render": function(data, type, row, meta) {
                    return "<a href = '@Url.Action("Edit", "Test1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title = \"Edit\"><i class='icon-edit fa fa-pencil fa-fw fa-lg'></i></a>" +
                        "<a href='@Url.Action("Copy", "CopyTest1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title=\"Duplicate\"><i class='icon-replicate fa fa-clipboard fa-fw fa-lg'></i></a>" +
                        "<a href='@Url.Action("Delete", "Test1")?companyId=" + row.CompanyID + "&profileId=" + row.ProfileID + "&clientId=" + row.ClientID+ "' title=\"Delete\" onclick=\"return ConfirmDelete()\"><i class='icon-red fa fa-times fa-lg fa-fw'></i></a>" ;
                }
            }
        ],
        "columnDefs": [ {
            "targets": [-1],
            "orderable": false,
            "searchable": false
        } ]

    });
    console.log("ready to work");

    function ConfirmDelete() {
        if (confirm('Are you sure to delete this?')) {
            return true;
        }
        else {
            return false;
        }
    }
});