我有一个引导项目,我使用datatables插入。我想在删除行之前添加确认。 当我首先用repeater和linkButton填充表格时,我可以正确地完成它。但我现在想要,只需发送我需要的信息。 然后我尝试使用服务器端模式。 这是我的代码:
$('#LBENEF').DataTable({
"aaSorting": [],
"processing": true,
"serverSide": true,
"ajax": "/Beneficiaire/ListBeneficiaires.asmx/GetListBenef",
"columnDefs": [{ "orderable": false, "targets": 6 }],
"columns": [
{ "data": null, },
{ "data": "TypeLibelle", },
{ "data": "ID_CLIENT" },
{ "data": "NomPrenom" },
{ "data": "SitLibelle" },
{ "data": "PerimLibelle" },
{ "data": null }
],
"createdRow": function (row, data, index) {
if (!data.Actif) { $('td', row).eq(0).html("<span Class='glyphicon glyphicon-ban-circle'></span>"); }
else { $('td', row).eq(0).html(""); }
if (data.PeutConsult) { $('td', row).eq(6).html('<a href="/edit.aspx?ID=' + data.ID + '"><span Class="glyphicon glyphicon-pencil"></span></a>'); }
if (data.PeutSup) { $('td', row).eq(6).append('<a onclick="DelBenef(' + data.ID + ');" data-toggle="confirmation" href="#"><span class="glyphicon glyphicon-trash"></span></a>'); }
},
drawCallback : function (oSettings) { $('[data-toggle="confirmation"]').confirmation(paramPopOverFileList); }
});
function DelBenef(IdBen) {
$.ajax(
{
type: "POST", url: "/toto.asmx/DelBenef", contentType: "application/json; charset=utf-8", dataType: "json", data:'{"IdBenef":' + IdBen + "}",
success: function (msg) {
if (msg.d.Reussi) { $('#LBENEF').DataTable().ajax.reload(); }
else { AfficheMsgRetour(msg.d); }
},
error: function () { //Code errors
}
});
}
我的表格看起来不错,我可以搜索或订购它,我可以编辑。我的问题是,当我点击垃圾桶图标时,我看到了我的弹出确认,但同时在toto.asmx / DelBenef上的DelBenef功能...... 有人有想法吗?
答案 0 :(得分:3)
我用弹出窗口创建了一个小提琴here(带有HTML内容)。为使其工作而执行的代码更改是 -
在drawcallback函数中
$("[data-toggle=confirmation]").confirmation({
title: "Confirmation required!",
html: true,
content: "<h1> Are you sure you want to delete </h1>",
onConfirm: function(event, element) {
alert('Replace this alert with your ajax call!');
}
});
createdRow
功能的更改仅适用于测试。您可以将其替换为代码中的图像。
希望这有帮助!
答案 1 :(得分:1)
答案 2 :(得分:0)
尝试在$.ajax
电话
function DelBenef(IdBen) ({
if (window.confirm("Do you really want to delete this ?")) {
$.ajax({
...
});
}
})