如您所见,我的视图中有此表:
<table id="DataTable" class="table table-condensed">
<thead>
<tr class="headings">
<th >نام و نام خانوادگی </th>
<th></th>
<th>وقت ملاقات </th>
<th>ملاقات شونده </th>
<th>زمان ورود </th>
<th>زمان خروج </th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
@foreach (ReferralTrafficView item in Model)
{
}
</tbody>
</table>
这是我的数据表配置:
<script>
$(document).ready(function () {
$('#DataTable').DataTable({
"paging": true,
"pageLength": 10,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "همه"]],
"ordering": true,
"processing": true,
"info": true,
"dom": "<'row'<'col-md-6 text-right'f><'col-md-6 text-left'>>"
+ "<'row'<'col-md-12'tr>>" +
"<'row'<'col-md-5 text-right rtl'p> <'col-md-7 text-left'i>>",
"language": {
"search": "_INPUT_",
"searchPlaceholder": "جستجو...", "sLoadingRecords": "در حال دریافت اطلاعات...", "sProcessing": "در حال پردازش...",
"lengthMenu": "نمایش _MENU_ ردیف در هر صفحه",
"zeroRecords": "موردی یافت نشد!",
"info": "نمایش صفحه _PAGE_ از _PAGES_",
"infoEmpty": "داده قابل نمایش موجود نیست.",
"infoFiltered": "(_TOTAL_ مورد از کل _MAX_ یافت شد)",
"oPaginate": {
"sNext": "<i class='fa fa-angle-left'></i>",
"sPrevious": "<i class='fa fa-angle-right'></i>"
}
}
});
});
</script>
我模型中的数据每次都更改,我想不刷新就刷新我的数据表。这是我的控制器:
public ActionResult MyReception(string Id)
{
List<ReferralTrafficView> rf = new List<ReferralTrafficView>();
get data from database
return rf
}
我可以将控制器设置为数据表配置以自动获取数据并刷新数据而无需重新加载页面吗?
答案 0 :(得分:0)
您必须使DataTable从ajax源收集其数据。 DataTables允许您配置将检索表内容的服务器端端点的URL。 然后添加一个onclick调用函数table.ajax.reload()的按钮。另外,您可能想使用setInterval()定期自动调用此函数。
查看有关设置switch statement和ajax source的文档。
另一种选择是更新表的数据部分并重新绘制网格。 ajax reload function