当没有数据时,如何阻止jQuery的dataTable插件添加行和消息 [英] How can I prevent the jquery dataTable plugin from adding row and message when there is no data

查看:358
本文介绍了当没有数据时,如何阻止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.

这是我用来初始化dataTable的代码。我知道这里的一些事情是错的。我一直在试验。 :)

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);

Dan

推荐答案

尝试这个

$('#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插件添加行和消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆