我使用jquery datatable进行用户的显示列表。对于删除我已经设置了一个标签。我点击标签我想从表中删除这个原始但我没有成功。我尝试一些波,但没有找到父标签,并删除原始。这下面我的代码=>
这是我的html =>
function LoadUsers(UserDdlFilter) {
oTable = $('#myDataTable').dataTable({
tableTools: {
'aButtons': [{
'sExtends': 'xls',
"sButtonText": "Download Excel"
}, ]
},
"oLanguage": {
"oPaginate": {
"sPrevious": '<i class="fa fa-angle-left"></i>',
"sNext": '<i class="fa fa-angle-right"></i>'
},
"sSearch": "",
"sProcessing": "<div class=\"cssload-container\" style=\"display:block;left:0%\" id=\"Loader\"><ul class=\"cssload-flex-container\"><li><span class=\"cssload-loading\"></span></li></ul></div>"
},
"lengthMenu": [
[100, 1000, 5000, 10000],
[100, 1000, 5000, 10000]
],
"bPaginate": true,
"bDestroy": true,
"bServerSide": true,
"processing": true,
//"dom": '<"top"ifl>rt<"bottom"p>',
//"sAjaxSource": '@Url.Action("GetUserList", "Users")',
"sAjaxSource": 'Users/GetUserList?UserDdlFilter=' + UserDdlFilter,
"fnServerData": function(sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function(json) {
document.getElementById("TotalUsers").innerHTML = json.TotalUsers;
fnCallback(json)
}).fail(function(jqxhr, textStatus, error) {
//window.location.reload();
});
},
"fnDrawCallback": function(oSettings) {
$("th:first").removeClass("sorting_asc");
$("[class='Toggle-Button']").bootstrapSwitch();
},
columnDefs: [{
orderable: false,
targets: -1
}],
//"order": [[ 3, "desc" ]],
"aoColumns": [{
"mData": "SrNo"
},
{
"mData": function(source) {
var resObj = {
'ProfileImage': source.ProfileImage
}
return resObj;
},
"mRender": function(resObj) {
var res = "";
if (resObj != "") {
var res = '<img src="' + resObj.ProfileImage + '" width="80" />';
}
return res;
}
},
{
"mData": "Name"
},
{
"mData": "UserName"
},
{
"mData": "Email"
},
{
"mData": "PhoneNo"
},
{
"mData": function(source) {
var resObj = {
'UserId': source.UserId
}
return resObj;
},
"mRender": function(resObj) {
var html = '<a href="javascript:void(0)" id="Delete_"' + resObj.UserId + '" onclick="DeleteUser(' + resObj.UserId + ')"><i data-toggle="tooltip" data-placement="top" title="Delete User" class="fa fa-trash delete"></i></a>';
return html;
}
}
]
});
这是我的ajax call =&gt;
函数DeleteUser(UserId){ if(确认(“你确定要删除”)){ var url ='@ Url.Action(“DeleteUser”,“Users”)';
$.ajax({
url: url,
data: {
UserId: UserId
},
cache: false,
type: 'POST',
async: false,
success: function(data) {
if (data.Result == "Success") {
$('#myDataTable a#Delete_' + UserId).remove(); // i want here remove raw from the table on click a tag.
$("#Loader").hide();
} else {
$("#Loader").show();
}
},
error: function(reponse) {
alert("error : " + reponse);
}
});
}
}
答案 0 :(得分:1)
好的,我检查了一下, 干得好。
$('a#Delete_' + UserId).parents('tr:first').remove();