【发布时间】:2016-08-16 16:59:21
【问题描述】:
我正在使用 jquery DataTable v 1.10.11 .. 我想隐藏整个表和显示它的 div,同时数据表通过 ajax 调用从服务器加载数据.. 我搜索但找到了初始化建议ajax 调用成功的表我不能做,因为我在同一个表上执行许多任务,如添加/编辑/删除。下面是我的 dataTable 声明。
$(document).ready(function (){
//some code ....
var listTable = $('#listTable').DataTable({
'fnCreatedRow': function (nRow, aData, iDataIndex) {
$(nRow).attr('id', 'my' + iDataIndex);
$(nRow).attr('name', 'my' + iDataIndex); // or whatever you choose to set as the id
},
"tableTools": {
"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "copy",
"sButtonText": "Copy To ClipBoard",
},
{
"sExtends": "xls",
"sFileName": "*.xls",
"sButtonText": "Download XLS",
},
{
"sExtends": "print",
}
]
},
"bInfo": false,
"sEmptyTable": "There are no records",
"processing": true,
"oLanguage": {
"sProcessing": "<img src='${request.contextPath}/images/ajax-loader.gif'>"
},
"dom": '<"toolbar">T<"clear">lfrtip',
"order": [[ 1, "desc" ]]
});
$('.dataTables_empty').html("");
//some more code
//some url
listTable.ajax.url(url).load()
});
下面是表格HTML代码
<div id="data_table_travelHistory" style="margin:0 auto; padding-top:10px; width:90%;">
<table cellpadding="0" cellspacing="0" border="0" id="listTable" style="width:100%;" class="table table-striped table-bordered">
<thead class="alignCenter">
<tr>
<th class="headerclass">Start Date</th>
<th class="headerclass">Approval Status</th>
<th class="headerclass">Created On</th>
<th class="headerclass">Action</th>
</tr>
</thead>
<tbody></tbody>
<tfoot class="alignCenter headerclass">
<tr>
<th class="headerclass">Start Date</th>
<th class="headerclass">Approval Status</th>
<th class="headerclass">Created On</th>
<th class="headerclass">Action</th>
</tr>
</tfoot>
</table>
</div>
目前我可以在加载 DataTable 时显示 gif 加载图像。但是初始化的表总是出现在后台,看起来不太好。有没有办法我可以隐藏整个 DataTable 和它所在的 div 并且只显示加载栏....任何帮助将不胜感激...
【问题讨论】:
标签: javascript jquery html ajax datatable