显示加载gif时,DataTable已被清除
Show loading gif when DataTable has been cleared
我有几个选项为我的JQuery数据表,这将清除数据表,并通过WebSockets加载新的数据。因此,我用fnClearTable()
清除表内容,过了一会儿,我通过WebSocket获得新数据。
这可以持续几秒钟,同时我想在我的数据表中显示一个加载图像。我怎样才能做到这一点呢?
清除DataTable的事件处理程序:
/* On Daterange change (e.g. Last 3 Days instead of Last 24h) */
$('#profitList_dateRange').change(function() {
var dateRangeHours = $("#profitList_dateRange").val();
var jsonParamObject = JSON.parse(dateRangeHours);
// Clear table
var profitList = $('#profitList').dataTable();
profitList.fnClearTable(); // Now I want to show the loading image!
socket.emit('load-statistics', (jsonParamObject));
});
实现它的一种方法是,如果你有两个div(我假设你的div是适当的样式,以其中的内容):
<div id="profitList"> your table content </div>
<div id="profitListLoading"> show loading here </div>
然后在处理程序中:
$('#profitList_dateRange').change(function() {
var dateRangeHours = $("#profitList_dateRange").val();
var jsonParamObject = JSON.parse(dateRangeHours);
// Clear table
var profitList = $('#profitList').dataTable();
profitList.fnClearTable(); // Now I want to show the loading image!
$('#profitList').hide();
$('#profitListLoading').show();
socket.emit('load-statistics', (jsonParamObject));
});
在处理加载的数据时,您应该使用。恢复更改
$('#profitList').show();
$('#profitListLoading').hide();
确保有processing: true
$('#example').dataTable({
processing: true
});
然后添加:
$('.dataTables_processing', $('#example').closest('.dataTables_wrapper')).show();
如果你想添加一个GIF图像,你可以改变标记如下:
$('#example').dataTable({
oLanguage: {
sProcessing: "<img src='https://d13yacurqjgara.cloudfront.net/users/12755/screenshots/1037374/hex-loader2.gif'>"
},
processing: true
});
: http://jsfiddle.net/0m6uo54t/2
处理:https://datatables.net/reference/option/processing启用或禁用'处理'指示器的显示正在处理的表(例如排序)。这个特别有用对于具有大量数据的表,它可能需要一个明显的排序条目所需的时间。
[UPDATE] bProcessing
是遗留选项,新的DT代码使用processing
相关文章:
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 单击jquery清除输入值
- 用我的json数据填充JQuery DataTable
- 如何在Microsoft VirtualEarth 6.3中使用纯javascript清除整个形状层
- 清除以前的$_GET值或不获取仅隐藏字段的值
- DataTable按下键选择扩展/导航
- 未捕获的类型错误:$(..).dataTable不是函数
- Javascript清除缓存以清除基本身份验证凭据
- timeago.js with datatable and PHP
- 使用KnockoutJS绑定的YUI DataTable
- 删除DataTable(1.10.8)后,删除的行将再次添加
- JQuery DataTable列筛选器-选择下拉筛选器
- Datatable get列值只给出前10行
- datatable append html,但已刷新
- 清除启动日期选取器值
- 在 SlickGrid 中编辑后,根据不同列中的另一个单元格清除单元格
- php页面,该页面在清除值后接受输入
- 如何在jQuery中使用onchange清除DataTable
- 显示加载gif时,DataTable已被清除
- jQuery datatable清除header中的单选按钮