这是我的Html代码:
<table class="table table-striped">
<thead>
<tr>
<th>Extension File Name</th>
<th>Action</th>
</tr>
</thead>
<tbody id="ExtTableBody">
@foreach (var item in Model.ExtSaved)
{
<tr>
<td>@item.FileName</td>
<td><a id="@item.Id" class="remove delete-user-row-with-ajax-button"><i class="icon-remove"></i></a></td>
</tr>
}
</tbody>
</table>
<script>
$(document).ready(function () {
$("table").DataTable();
});
</script>
还有脚本:
<script>
$(document).ready(function () {
$("table").DataTable();
});
</script>
<script>
$("a.delete-user-row-with-ajax-button").bootstrap_confirm_delete({
callback: function (e) {
var button = e.data.originalObject;
var Id = button.attr('id');
$.ajax({
type: "POST",
datatype: "application/json",
url: "/UploadFile/Remove",
data: { Id: Id },
success: function (data) {
if (data.UpdateDB == true) {
if (data.success > 0) {
button.closest('tr').remove();
$('#ExtSuccessText3').text("Extension File Removed Successufully.").removeClass("errormsg").addClass("successmsg");
}
}
}
});
}
});
</script>
我的行动:
[HttpPost]
public ActionResult Remove(string Id)
{
int success = 1;
ED.DELETEEXTENSIONBYID(Id);
TempData["Message"] = "Extension successufully removed.";
return Json(new { UpdateDB = true, success = success }, JsonRequestBehavior.AllowGet);
}
打开页面时:
删除行后:
所以我不知道自己要做什么。
答案 0 :(得分:1)
您需要从DataTable中删除该行:
<script>
var table //add an global variable
$(document).ready(function () {
table = $("table").DataTable();
});
</script>
<script>
$("a.delete-user-row-with-ajax-button").bootstrap_confirm_delete({
callback: function (e) {
var button = e.data.originalObject;
var Id = button.attr('id');
$.ajax({
type: "POST",
datatype: "application/json",
url: "/UploadFile/Remove",
data: { Id: Id },
success: function (data) {
if (data.UpdateDB == true) {
if (data.success > 0) {
//remove the row from datatable
table.row( button.closest('tr') )
.remove()
.draw();
$('#ExtSuccessText3').text("Extension File Removed Successufully.").removeClass("errormsg").addClass("successmsg");
}
}
}
});
}
});
</script>
答案 1 :(得分:0)
从Codeigniter
尝试此示例//add this at the top of your page
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
//assign a variable on your datatable
var dataTable;
$(document).ready(function() {
dataTable = $('#manufacturer_data').DataTable({
"ajax": "<?=base_url()?>manufacturer/manufacturer_list",
});
});
success: function(){
//if your ajax call is success call the dataTable variable to make it reload
dataTable.ajax.reload(null, false);
}
//add this at the bottom of your page
<script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>