Hammad Bukhari
Hammad Bukhari

Reputation: 83

Delete confirmation message in jquery datatables

I am using jquery datatables in my asp.net mvc application. I just want to enable confirmation popup when user presses the delete button for particular row. i cant find any solution over the internet that works. below is my script for datatable in razor view.

Razor View Script

<script type="text/javascript">

$('#example').dataTable({

    //scrollY: "300px",
    //scrollX: false,
    //scrollCollapse : true,
    //"iDisplayLength": 100,
    //"iDisplayStart": 0,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/UsersAPI/LoadUsers",
    //"sServerMethod": "POST",
    //"sAjaxDataProp": "",
    "aoColumns": [
        { "mData": "Id", "sWidth": "10%" },
        { "mData": "Email", "sWidth": "30%" },
        { "mData": "FirstName", "sWidth": "25%" },
        { "mData": "LastName", "sWidth": "25%" },
        { "mData": "RoleName", "sWidth": "40%" },
        { "mData": "AccountName", "sWidth": "40%" },
      {

          "mRender": function (data, type, row) {
              //return data + ' ' + row[3];
              return '<a href=' +
                           '@Url.Action("Edit", "Users")?Email=' + row.Email +
                        '>Edit</a>';
          }              
      },
      {

          "mRender": function (data, type, row) {
              //return data + ' ' + row[3];
              return '<a href=' +
                           '@Url.Action("Delete", "Users")?Id=' + row.Id +
                        '>Delete</a>';
          }
      }
      ]

});   

Upvotes: 0

Views: 1973

Answers (1)

davidkonrad
davidkonrad

Reputation: 85518

I would assign a class to the delete link :

"mRender": function (data, type, row) {
              return '<a class="delete" href=' +
                     '@Url.Action("Delete", "Users")?Id=' + row.Id +
                     '>Delete</a>';
           }

By that it should be no problem to cancel a click on the delete link :

$("a.delete").on('click', function() {
    return confirm('Really delete?');
});

Upvotes: 2

Related Questions