【发布时间】:2018-08-10 14:26:07
【问题描述】:
我有 jquery 函数来在列数据表中给出数字并从删除按钮删除执行。当我尝试删除表中的数据时,它无法再次重新排序。 这是我的问题。
应该从1-4重新排序。 table_id 是我的 id 表。
这是我的HTML代码:
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover js-basic-example dataTable" id="table_id">
<thead>
<tr>
<th width="10px">#</th>
<th>Bagian</th>
<th width="90px">Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>#</th>
<th>Bagian</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
@if (ViewBag.JabatanList != null)
{
foreach (var item in ViewBag.JabatanList)
{
<tr id="row_@item.JabatanId">
<td></td>
<td>@item.NamaJabatan</td>
<td>
<a href="@Url.Action("CreateEdit","Jabatan",new { Id = item.JabatanId })" class="btn bg-blue waves-effect" title="Ubah"><i class="material-icons">edit</i></a>
<a href="#" class="btn bg-red waves-effect" title="Hapus" data-type="confirm" onclick="ConfirmDelete(@item.JabatanId)"><i class="material-icons">delete</i></a>
</td>
</tr>
}
}
</tbody>
</table>
</div>
@*catch JabatanId*@
<input type="hidden" id="hiddenJabatanId" />
这是我的 AJAX 代码:
<script type="text/javascript">
$(document).ready(function () {
RowNumber(); //calling row number function
});
var RowNumber = function () {
var table = $('#table_id').DataTable({
//default show entries
"aLengthMenu": [[10, 25, 50, 75, 100, -1], [10, 25, 50, 75, 100, "All"]],
"iDisplayLength": 25,
//row number
"columnDefs": [{
"searchable": false,
"orderable": false,
"targets": 0
}]
});
table.on('order.dt search.dt', function () {
table.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
}
var ConfirmDelete = function (JabatanId) {
$("#hiddenJabatanId").val(JabatanId); //passing value JabatanId
}
var DeleteBagian = function () {
var bgnId = $("#hiddenBagianId").val();
//debugger
$.ajax({
type: "POST",
url: "/Bagian/Delete",
data: { Id: bgnId },
success: function (result) {
$("#row_" + bgnId).remove(); //after remove row that succesfull delete, will re-order auto number again
$(document).ready(); //here i call document ready in order to reorder auto number
}
});
}
</script>
我尝试了几种方法来做到这一点,我尝试调用
对此案有任何建议,我将不胜感激。
【问题讨论】:
-
你能发布你所有的html吗?使用操作按钮?
-
@AkshayKriti 我为上面的 html 代码添加了
-
你试过我的解决方案了吗?我希望这会奏效。
标签: jquery asp.net-mvc html-table datatables