8

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": ''
    }
});

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

5 Answers 5

8

try this

$('#InBox').dataTable({
  "bFilter": false,
   "bPaginate": false,
   "bLengthChange": false,
   "bInfo": false,
   "oLanguage": {
    "sEmptyTable": '',
    "sInfoEmpty": ''
   },
   "sEmptyTable": "There are no records",
 });

otherwise you can try this

$('#InBox').dataTable({
  "bFilter": false,
   "bPaginate": false,
   "bLengthChange": false,
   "bInfo": false,
   "oLanguage": {
    "sEmptyTable": '',
    "sInfoEmpty": ''
   }
 });
$('.dataTables_empty').html("No record found.");
Sign up to request clarification or add additional context in comments.

1 Comment

My goal is to not show any message when the table is empty. I would prefer the row not be created. I have a button that adds rows to the dataTable. I will just need to add logic to remove the 'dataTables_empty' row before adding new rows. I used your code. I just set empty quotes so that their was no message. I will mark your answer as answer, if a more elegant way is not presented. Thanks for your help.
7

If you want to remove the tbody attacched from datatable plugin, you can try this workaround:

$('.dataTables_empty').parent().parent().remove();

Comments

3

Old post, but for the sake of people using search engines looking for the right answer here is how I accomplished.

Delete or comment out the following line from the dataTables source:

anRows[iRowCount].appendChild(nTd);

In the minified version, search and delete:

b[i].appendChild(c);

Comments

2

You can customize DataTable plugin by using oLanguange:

"oLanguage": { "sZeroRecords": "-Put customized text-", "sEmptyTable": "-Put customized text-" }

And if you want to remove those, just put these components into null:
"oLanguage": { "sZeroRecords": '', "sEmptyTable": '' }

Hope it helps!

Comments

2

The most current way to hide the messages is by using the language option

$('#loggedMessages').DataTable({
    "language": {
       "emptyTable": ' ',
       "zeroRecords": ' '
     }
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.