本文介绍了没有数据时如何防止jquery dataTable插件添加行和消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当表中没有数据时,我们的产品负责人希望我们的空表只显示表头.我似乎无法阻止 dataTable 创建带有空..."消息的行.
Our product owner would like the our empty tables to display just table header when there is no data in table. I can't seem to prevent dataTable from creating a row with "empty..." message.
这是我用来初始化数据表的代码.我知道这里有些事情是错误的.我一直在试验.:)
Here is the code I use to initialize the dataTable. I know some things here are wrong. I have been experimenting. :)
$('#InBox').dataTable({
"bFilter": false,
"bPaginate": false,
"bLengthChange": false,
"bInfo": false,
"oLanguage": {
"sEmptyTable": '',
"sInfoEmpty": ''
}
});
这是我尝试在 dataTable 的 init 函数中放入的一些代码,但我不知道如何让它工作.
Here is some code I tried to put in the init function of the dataTable, but I am not sure how to get it to work.
/* Table is empty - create a row with an empty message in it */
var anRows[0] = document.createElement('tr');
if (typeof oSettings.asStripClasses[0] != 'undefined') {
anRows[0].className = oSettings.asStripClasses[0];
}
var nTd = document.createElement('td');
nTd.setAttribute('valign', "top");
nTd.colSpan = oSettings.aoColumns.length;
nTd.className = oSettings.oClasses.sRowEmpty;
if (oSettings.fnRecordsTotal() > 0) {
if (oSettings.oLanguage.sZeroFilterRecords.indexOf("_MAX_") != -1)
oSettings.oLanguage.sZeroFilterRecords = oSettings.oLanguage.sZeroFilterRecords.replace("_MAX_", oSettings.fnRecordsTotal());
nTd.innerHTML = oSettings.oLanguage.sZeroFilterRecords;
} else {
nTd.innerHTML = oSettings.oLanguage.sZeroRecords;
}
anRows[iRowCount].appendChild(nTd);
丹
推荐答案
试试这个
$('#InBox').dataTable({
"bFilter": false,
"bPaginate": false,
"bLengthChange": false,
"bInfo": false,
"oLanguage": {
"sEmptyTable": '',
"sInfoEmpty": ''
},
"sEmptyTable": "There are no records",
});
否则你可以试试这个
$('#InBox').dataTable({
"bFilter": false,
"bPaginate": false,
"bLengthChange": false,
"bInfo": false,
"oLanguage": {
"sEmptyTable": '',
"sInfoEmpty": ''
}
});
$('.dataTables_empty').html("No record found.");
这篇关于没有数据时如何防止jquery dataTable插件添加行和消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!